예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
 public static Models.Catalog FromDBCatalogToCatalog(DB.Catalog catalog)
 {
     return(new Models.Catalog()
     {
         Category = catalog.CategoryName,
         Name = catalog.Name,
         Price = catalog.Price,
         Quantity = catalog.Quantity
     });
 }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }