public void Return_0_When_Not_Contains_Passed_Catalog() { //Arrange var commonServiceMock = new Mock <ICommonService>(); var categoryServiceMock = new Mock <ICategoryService>(); var ruleMock = new Mock <ICalculatePriceRule>(); var rules = new List <ICalculatePriceRule>() { ruleMock.Object }; var dbCatalog = new DB.Catalog("TEST1", "TEST1", 3, 3); var dbCollection = new List <DB.Catalog>() { dbCatalog }; var myDbMock = new Mock <IMyDB>(); myDbMock.Setup(x => x.Catalogs).Returns(dbCollection); var catalogService = new CatalogService(myDbMock.Object); var store = new Store(commonServiceMock.Object, categoryServiceMock.Object, catalogService, rules); //Act var result = store.Quantity("test4e"); //Assert Assert.AreEqual(0, result); }
public void Return_Correct_Price_When_Pass_One_Book() { //Arrange var rules = new HashSet <ICalculatePriceRule>() { new SinglePriceRule() }; var dbCatalog = new DB.Catalog("TEST1", "TEST1", 4, 4); var dbCollectionCategory = new List <DB.Category>() { new DB.Category("TEST1", 0.1) }; var dbCollection = new List <DB.Catalog>() { dbCatalog }; var myDbMock = new Mock <IMyDB>(); myDbMock.Setup(x => x.Catalogs).Returns(dbCollection); myDbMock.Setup(x => x.Categories).Returns(dbCollectionCategory); var categoryService = new CategoryService(myDbMock.Object); var catalogService = new CatalogService(myDbMock.Object); var commonServiceMock = new CommonService(categoryService, catalogService); var store = new Store(commonServiceMock, categoryService, catalogService, rules); //Act var result = store.Buy("TEST1"); //Assert Assert.AreEqual(4, result); }
public void ReturnCorrectCatalogWhenContains() { //Arrange var dbCatalog = new DB.Catalog("TEST1", "TEST1", 3, 3); var dbCollection = new List <DB.Catalog>() { dbCatalog }; var myDbMock = new Mock <IMyDB>(); myDbMock.Setup(x => x.Catalogs).Returns(dbCollection); var catalogService = new CatalogService(myDbMock.Object); //Act var result = catalogService.GetCatalog("TEST1"); //Assert Assert.AreEqual("TEST1", result.Name); Assert.AreEqual("TEST1", result.Category); Assert.AreEqual(3, result.Price); Assert.AreEqual(3, result.Quantity); }
public void ReturnAllBookTittles() { //Arrange var dbCatalog = new DB.Catalog("TEST1", "TEST1", 3, 3); var dbCatalog2 = new DB.Catalog("TEST2", "TEST1", 3, 3); var dbCatalog3 = new DB.Catalog("TEST3", "TEST1", 3, 3); var dbCollection = new List <DB.Catalog>() { dbCatalog, dbCatalog2, dbCatalog3 }; var myDbMock = new Mock <IMyDB>(); myDbMock.Setup(x => x.Catalogs).Returns(dbCollection); var catalogService = new CatalogService(myDbMock.Object); //Act var result = catalogService.GetBookTitles(); //Assert Assert.AreEqual(3, result.Count); }
public static Models.Catalog FromDBCatalogToCatalog(DB.Catalog catalog) { return(new Models.Catalog() { Category = catalog.CategoryName, Name = catalog.Name, Price = catalog.Price, Quantity = catalog.Quantity }); }
public void ReturnCorrectData() { //Arange var dbCatalog = new DB.Catalog("TEST1", "TEST1", 3, 3); var dbCollection = new List<DB.Catalog>() { dbCatalog }; var myDbMock = new Mock<IMyDB>(); myDbMock.Setup(x => x.Catalogs).Returns(dbCollection); var catalogService = new CatalogService(myDbMock.Object); //Act var result = catalogService.GetAll(); //Assert Assert.AreEqual(1, result.Count); }
public void ReturnDefaultWhenNotContains() { //Arrange var dbCatalog = new DB.Catalog("TEST1", "TEST1", 3, 3); var dbCollection = new List <DB.Catalog>() { dbCatalog }; var myDbMock = new Mock <IMyDB>(); myDbMock.Setup(x => x.Catalogs).Returns(dbCollection); var catalogService = new CatalogService(myDbMock.Object); //Act var result = catalogService.GetCatalog("TEST2"); //Assert Assert.AreEqual(default(DB.Catalog), result); }
public void Return_Correct_Price_When_Pass_Two_Books_From_Same_Category() { //Arrange var rules = new List <ICalculatePriceRule>() { new SeveralBooksRule() }; var dbCatalog = new DB.Catalog("TEST1", "TEST1", 10, 4); var dbCatalog2 = new DB.Catalog("TEST2", "TEST1", 10, 4); var dbCollectionCategory = new List <DB.Category>() { new DB.Category("TEST1", 0.1) }; var dbCollection = new List <DB.Catalog>() { dbCatalog, dbCatalog2 }; var myDbMock = new Mock <IMyDB>(); myDbMock.Setup(x => x.Catalogs).Returns(dbCollection); myDbMock.Setup(x => x.Categories).Returns(dbCollectionCategory); var categoryService = new CategoryService(myDbMock.Object); var catalogService = new CatalogService(myDbMock.Object); var commonServiceMock = new CommonService(categoryService, catalogService); var store = new Store(commonServiceMock, categoryService, catalogService, rules); //Act var result = store.Buy("TEST1", "TEST2"); //Assert Assert.AreEqual(18, result); }