473,383 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

No overload for method - retrieving from generic list

Trying to run an NUnit test to store and retrieve an item and ensure that the item retrieved is the same as the item stored.
Expand|Select|Wrap|Line Numbers
  1.         public void TestStoreAndRetrieve()
  2.         {
  3.             Factory factory = Factory.GetInstance();
  4.             IBookService bookSvc = (IBookService)factory.GetService(typeof(IBookService).Name);
  5.             Book book1 = new Book("9781426829758", "Stock", "Dark Rival", "Masters of Time", "Brenda Joyce", "Time Travel");
  6.             bookSvc.StoreBook(book1);
  7.             Book book2 = bookSvc.RetrieveBook();
  8.             Assert.AreEqual(book1, book2);
  9.  
Getting an error that there is no overload for method RetrieveBook that takes 0 arguments.
I have updated all my code to put the books in a list, this is when the issues started. Not sure what I am supposed to be calling with RetrieveBook though.

Expand|Select|Wrap|Line Numbers
  1.     public interface IBookService : IService
  2.     {
  3.         void StoreBook(Book bookx);
  4.         void StoreBookList(Book[] bookx);
  5.         void RetrieveBook(Book bookx);
  6.         Book[] RetrieveBookList(int maxcount);
  7.         //Book RetrieveBook();
  8.     }
  9.  
Expand|Select|Wrap|Line Numbers
  1.         public void RetrieveBook(Book bookx)
  2.         {
  3.             FileStream loadStream = new FileStream("Book.bin", FileMode.Open, FileAccess.Read);
  4.             IFormatter formatter = new BinaryFormatter();
  5.             IList<Book> listBooks = formatter.Deserialize(loadStream) as IList<Book>;
  6.             //Book bookX = formatter.Deserialize(loadStream) as Book;
  7.             loadStream.Close();
  8.             //return bookX;
  9.         }
  10.  
Oct 13 '10 #1
5 1701
Method RetrieveBook have a param, so it can't be called without it...
Expand|Select|Wrap|Line Numbers
  1.         public void TestStoreAndRetrieve()
  2.         {
  3.             Factory factory = Factory.GetInstance();
  4.             IBookService bookSvc = (IBookService)factory.GetService(typeof(IBookService).Name);
  5.             Book book1 = new Book("9781426829758", "Stock", "Dark Rival", "Masters of Time", "Brenda Joyce", "Time Travel");
  6.             bookSvc.StoreBook(book1);
  7.             Book book2 = bookSvc.RetrieveBook(book1);
  8.             Assert.AreEqual(book1, book2);
  9.  
Oct 13 '10 #2
Plater
7,872 Expert 4TB
Yeah you clearly are calling:
Book book2 = bookSvc.RetrieveBook();
and also clearly have this line:
//Book RetrieveBook();

The error message is telling you what is wrong. (Although I wonder why you have your function calls the way you do)
Oct 13 '10 #3
When i put book1 in
Expand|Select|Wrap|Line Numbers
  1. Book book2 = bookSvc.RetrieveBook(book1);
  2.  
I get error cannot implicitly convert type 'void' to Domain.Book.
Oct 13 '10 #4
Got it! Thanks for the help.
Oct 13 '10 #5
hype261
207 100+
Look at your function declaration.

Expand|Select|Wrap|Line Numbers
  1. public void RetrieveBook(Book bookx)
You are telling the compiler that this function doesn't return anything. To return a Book change the definition to.

Expand|Select|Wrap|Line Numbers
  1. public Book Retrievebook(Book bookx)
  2. {
  3. //what ever logic you get to return your book goes here
  4. return book; 
  5. }
You will also need to change the method definition in your interface IBookService.
Oct 13 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael Rockwell | last post by:
I am new to using C# generics and I am liking what I am finding. However the examples in online help are lacking. Can someone help me with the FindAll method of the generic List class? As I...
5
by: majm | last post by:
I'm trying to implement strongly typed lists in the 2.0 framework. I'm using VS2005 beta 2. So far, System.Collections.Generic.List appears to be the ideal solution. However, the...
2
by: Richard Bysouth | last post by:
I'm sure this is something pretty trivial but can't seem to figure out how to do it. I'm using Generic Lists in quite a few places in my app and for some of them want to be able to create a...
4
by: rsa_net_newbie | last post by:
Hi there, I have a Managed C++ object (in a DLL) which has a method that is defined like ... Generic::List<String^>^ buildList(String^ inParm) Now, when I compile it, I get "warning C4172:...
3
by: Peter Olcott | last post by:
How does not specify the sort criteria for Generic.List ?? The way that this is done in C++ STL is to implement operator<(), how is this done in C# and DotNet for Generic.List ???
7
by: Sehboo | last post by:
We have several generic List objects in our project. Some of them have about 1000 items in them. Everytime we have to find something, we have to do a for loop. There is one method which does the...
1
by: Kuldeep | last post by:
Framework: Visual Studio 2005, ASP.NET Programing Language: C#.NET I am using a Generic List Collection to fetch a particular master data from the database. Once collected, I use this Collection...
1
by: Radenko Zec | last post by:
Hi i have generic list problem with DAL code. class UlazTotal {
3
by: Doug | last post by:
I have a generic list object with a property called, "MarkedForDeletion". During the course of my processing, some of the objects in the list will get this property set to true and so at the end...
3
by: Fresno Bob | last post by:
I have a generic collection of objects and I would like to find the object by one of it's properties e.g. I would like something with the functionality of something like...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.