예제 #1
0
        public async Task GetAllProducts_WithDummyData_ShouldReturnCorrectResults()
        {
            var errorMsgPrefix = "ProductService GetAllProducts() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            SeedData(context);
            this.productService = new ProductService(context);


            var actualResult = await this.productService.GetAllProducts().ToListAsync();

            var expectedResult = GetDummyData().To <ProductServiceModel>().ToList();

            for (int i = 0; i < expectedResult.Count; i++)
            {
                var expectedEntry = expectedResult[i];
                var actualEntry   = actualResult[i];

                Assert.True(expectedEntry.Name == actualEntry.Name, errorMsgPrefix + " Name is not returned properly.");
                Assert.True(expectedEntry.Price == actualEntry.Price, errorMsgPrefix + " Price is not returned properly.");
                Assert.True(expectedEntry.Picture == actualEntry.Picture, errorMsgPrefix + " Picture is not returned properly.");
                Assert.True(expectedEntry.ProductType.Name == actualEntry.ProductType.Name, errorMsgPrefix + " ProductType is not returned properly.");
            }
        }
예제 #2
0
        public async Task Create_WithCorrectData_ShouldSuccessfullyCreate()
        {
            var errorMsgPrefix = "ProductService Create() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            SeedData(context);
            this.productService = new ProductService(context);

            var testProductService = new ProductServiceModel
            {
                Name           = "Pesho",
                Price          = 5,
                ManufacturedOn = DateTime.UtcNow,
                Picture        = "src/res/default.png",
                ProductType    = new ProductTypeServiceModel
                {
                    Name = "Television",
                }
            };

            var actualResult = await this.productService.Create(testProductService);

            Assert.True(actualResult, errorMsgPrefix);
        }
예제 #3
0
        public async Task SetOrdersToReceipt_WithCorrectData_ShouldSuccessfullySetOrdersToReceipt()
        {
            string errorMessagePrefix = "OrderService SetOrdersToReceipt() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            #region Dummy Data
            context.Orders.Add(new Order
            {
                IssuerId = "1",
                Status   = new OrderStatus
                {
                    Name = "Active"
                }
            });
            context.Receipts.Add(new Receipt
            {
                RecipientId = "1"
            });
            await context.SaveChangesAsync();

            #endregion

            this.orderService = new OrderService(context);

            Receipt testReceipt = context.Receipts.First();
            await this.orderService.SetOrdersToReceipt(testReceipt);

            int expectedCountOfOrders = 1;
            int actualCountOfOrders   = context.Receipts.First().Orders.Count;

            Assert.True(expectedCountOfOrders == actualCountOfOrders, errorMessagePrefix);
        }
예제 #4
0
        public async Task GetAll_WithDummyData_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "OrderService GetAll() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.orderService = new OrderService(context);

            List <OrderServiceModel> actualResults = await this.orderService.GetAll()
                                                     .ToListAsync();

            List <OrderServiceModel> expectedResults = context.Orders
                                                       .To <OrderServiceModel>().ToList();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry.Quantity == actualEntry.Quantity, errorMessagePrefix + " " + "Quantity is not returned properly.");
                Assert.True(expectedEntry.IssuedOn == actualEntry.IssuedOn, errorMessagePrefix + " " + "Issued On is not returned properly.");
                Assert.True(expectedEntry.Status.Name == actualEntry.Status.Name, errorMessagePrefix + " " + "Status is not returned properly.");
            }
        }
예제 #5
0
        public async Task Edit_WithCorrectData_ShouldEditProductCorrectly()
        {
            var errorMsgPrefix = "ProductService Edit() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            SeedData(context);
            this.productService = new ProductService(context);

            var expectedData = context.Products.First().To <ProductServiceModel>();

            expectedData.Name           = "Editted Name";
            expectedData.Price          = 0.01M;
            expectedData.ManufacturedOn = DateTime.UtcNow;
            expectedData.Picture        = "Editted Picture";
            expectedData.ProductType    = context.ProductTypes.Last().To <ProductTypeServiceModel>();

            await this.productService.Edit(expectedData.Id, expectedData);

            var actualData = context.Products.First().To <ProductServiceModel>();

            Assert.True(actualData.Name == expectedData.Name, errorMsgPrefix + " Name not editted properly.");
            Assert.True(actualData.Price == expectedData.Price, errorMsgPrefix + " Price not editted properly.");
            Assert.True(actualData.ManufacturedOn == expectedData.ManufacturedOn, errorMsgPrefix + " ManufacturedOn not editted properly.");
            Assert.True(actualData.Picture == expectedData.Picture, errorMsgPrefix + " Picture not editted properly.");
            Assert.True(actualData.ProductType.Name == expectedData.ProductType.Name, errorMsgPrefix + " ProductType Name not editted properly.");
        }
예제 #6
0
        public async Task GetAllProducts_WithDummyDataOrderedByPriceAscending_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "ProductService GetAllProducts() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.productService = new ProductService(context);

            List <ProductServiceModel> actualResults = await this.productService.GetAllProducts("price-lowest-to-highest").ToListAsync();

            List <ProductServiceModel> expectedResults = GetDummyData()
                                                         .OrderBy(product => product.Price)
                                                         .To <ProductServiceModel>().ToList();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry.Name == actualEntry.Name, errorMessagePrefix + " " + "Name is not returned properly.");
                Assert.True(expectedEntry.Price == actualEntry.Price, errorMessagePrefix + " " + "Price is not returned properly.");
                Assert.True(expectedEntry.Picture == actualEntry.Picture, errorMessagePrefix + " " + "Picture is not returned properly.");
                Assert.True(expectedEntry.ProductType.Name == actualEntry.ProductType.Name, errorMessagePrefix + " " + "Product Type is not returned properly.");
            }
        }
예제 #7
0
        public async Task GetAllByRecipientId_WithCorrectData_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "ReceiptService GetAllByRecipient() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            #region Dummy Data

            context.Users.Add(new StopifyUser());

            await context.SaveChangesAsync();

            context.Receipts.Add(new Receipt
            {
                IssuedOn  = DateTime.UtcNow.AddDays(10),
                Recipient = context.Users.First()
            });
            context.Receipts.Add(new Receipt
            {
                IssuedOn  = DateTime.UtcNow.AddDays(5),
                Recipient = context.Users.First()
            });

            await context.SaveChangesAsync();

            #endregion

            this.receiptService = new ReceiptService(context, new OrderService(context));

            string testId = context.Users.First().Id;

            List <ReceiptServiceModel> actualResults = await this.receiptService.GetAllByRecipientId(testId).ToListAsync();

            Assert.True(actualResults.Count == 2, errorMessagePrefix);
        }
예제 #8
0
        public async Task Delete_WithNonExistentProductId_ShouldThrowArgumentNullException()
        {
            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            SeedData(context);
            this.productService = new ProductService(context);

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.productService.DeleteById("Non existend"));
        }
예제 #9
0
        public async Task GetAll_WithZeroData_ShouldReturnEmptyResults()
        {
            string errorMessagePrefix = "OrderService GetAll() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            this.orderService = new OrderService(context);

            List <OrderServiceModel> actualResults = await this.orderService.GetAll().ToListAsync();

            Assert.True(actualResults.Count == 0, errorMessagePrefix);
        }
예제 #10
0
        public async Task ReduceQuantity_WithNonExistentId_ShouldThrowArgumentNullException()
        {
            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.orderService = new OrderService(context);

            string testId = "Non_Existent";

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.orderService.ReduceQuantity(testId));
        }
예제 #11
0
        public async Task CompleteOrder_WithNonActiveStatus_ShouldThrowArgumentException()
        {
            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.orderService = new OrderService(context);

            string testId = context.Orders.FirstOrDefault(order => order.Status.Name != "Active").Id;

            await Assert.ThrowsAsync <ArgumentException>(() => this.orderService.CompleteOrder(testId));
        }
예제 #12
0
        public async Task Delete_WithNonExistentProductId_ShouldThrowArgumentNullException()
        {
            string errorMessagePrefix = "ProductService Delete() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.productService = new ProductService(context);

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.productService.Delete("Non-Existent"));
        }
예제 #13
0
        public async Task GetAllProductTypes_WithZeroData_ShouldReturnEmptyResults()
        {
            var errorMsgPrefix = "ProductService GetAllProductTypes() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            this.productService = new ProductService(context);

            var actualResult = await this.productService.GetAllProductTypes().ToListAsync();

            Assert.True(actualResult.Count == 0, errorMsgPrefix);
        }
예제 #14
0
        public async Task GetById_WithNonExistentId_ShouldReturnNull()
        {
            var errorMsgPrefix = "ProductService GetById() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            SeedData(context);
            this.productService = new ProductService(context);

            var actualData = await this.productService.GetById("prakash");

            Assert.True(actualData == null, errorMsgPrefix + " Id is not returned properly.");
        }
예제 #15
0
        public async Task Delete_WithCorrectData_ShouldPassSuccessfully()
        {
            var errorMsgPrefix = "ProductService Delete() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            SeedData(context);
            this.productService = new ProductService(context);

            var testId       = context.Products.First().To <ProductServiceModel>().Id;
            var actualResult = await this.productService.DeleteById(testId);

            Assert.True(actualResult, errorMsgPrefix);
        }
예제 #16
0
        public async Task CreateOrder_WithCorrectData_ShouldSuccessfullyCreateOrder()
        {
            string errorMessagePrefix = "OrderService Create() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.orderService = new OrderService(context);

            OrderServiceModel testReceipt = new OrderServiceModel();

            bool actualResult = await this.orderService.CreateOrder(testReceipt);

            Assert.True(actualResult, errorMessagePrefix);
        }
예제 #17
0
        public async Task Delete_WithCorrectData_ShouldPassSuccessfully()
        {
            string errorMessagePrefix = "ProductService Delete() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.productService = new ProductService(context);

            string testId = context.Products.First().To <ProductServiceModel>().Id;

            bool actualData = await this.productService.Delete(testId);

            Assert.True(actualData, errorMessagePrefix);
        }
예제 #18
0
        public async Task Edit_WithNonExistentProductType_ShouldThrowArgumentNullException()
        {
            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            SeedData(context);
            this.productService = new ProductService(context);

            var expectedData = context.Products.First().To <ProductServiceModel>();

            expectedData.Name           = "Editted Name";
            expectedData.Price          = 0.01M;
            expectedData.ManufacturedOn = DateTime.UtcNow;
            expectedData.Picture        = "Editted Picture";
            expectedData.ProductType    = context.ProductTypes.Last().To <ProductTypeServiceModel>();

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.productService.Edit("Non existent", expectedData));
        }
예제 #19
0
        public async Task CreateProductType_WithCorrectData_ShouldSuccessfullyCreate()
        {
            var errorMsgPrefix = "ProductService CreateProductType() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            this.productService = new ProductService(context);

            var testProductType = new ProductTypeServiceModel
            {
                Name = "Pesho",
            };

            var actualResult = await this.productService.CreateProductType(testProductType);

            Assert.True(actualResult, errorMsgPrefix);
        }
예제 #20
0
        public async Task GetById_WithExistentId_ShouldReturnCorrectResult()
        {
            var errorMsgPrefix = "ProductService GetById() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            SeedData(context);
            this.productService = new ProductService(context);

            var expectedData = context.Products.First().To <ProductServiceModel>();
            var actualData   = await this.productService.GetById(expectedData.Id);

            Assert.True(expectedData.Id == actualData.Id, errorMsgPrefix + " Id is not returned properly.");
            Assert.True(expectedData.Name == actualData.Name, errorMsgPrefix + " Name is not returned properly.");
            Assert.True(expectedData.Price == actualData.Price, errorMsgPrefix + " Price is not returned properly.");
            Assert.True(expectedData.Picture == actualData.Picture, errorMsgPrefix + " Picture is not returned properly.");
            Assert.True(expectedData.ProductType.Name == actualData.ProductType.Name, errorMsgPrefix + " ProductType is not returned properly.");
        }
예제 #21
0
        public async Task CompleteOrder_WithExistentId_ShouldSuccessfullyCompleteOrder()
        {
            string errorMessagePrefix = "OrderService CompleteOrder() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.orderService = new OrderService(context);

            string testId = context.Orders.First().Id;

            await this.orderService.CompleteOrder(testId);

            Order testOrder = context.Orders.First();

            Assert.True(testOrder.Status.Name == "Completed", errorMessagePrefix);
        }
예제 #22
0
        public async Task ReduceQuantity_WithExistentIdAndOneQuantity_ShouldNotReduceQuantity()
        {
            string errorMessagePrefix = "OrderService ReduceQuantity() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.orderService = new OrderService(context);

            OrderServiceModel testOrder = context.Orders.First(order => order.Quantity == 1).To <OrderServiceModel>();

            await this.orderService.ReduceQuantity(testOrder.Id);

            int expectedQuantity = 1;
            int actualQuantity   = context.Orders.First(order => order.Id == testOrder.Id).Quantity;

            Assert.True(expectedQuantity == actualQuantity, errorMessagePrefix);
        }
예제 #23
0
        public async Task Edit_WithNonExistentProductId_ShouldThrowArgumentNullException()
        {
            string errorMessagePrefix = "ProductService Edit() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.productService = new ProductService(context);

            ProductServiceModel expectedData = context.Products.First().To <ProductServiceModel>();

            expectedData.Name           = "Editted_Name";
            expectedData.Price          = 0.01M;
            expectedData.ManufacturedOn = DateTime.UtcNow;
            expectedData.Picture        = "Editted_Picture";
            expectedData.ProductType    = context.ProductTypes.Last().To <ProductTypeServiceModel>();

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.productService.Edit("Non-Existent", expectedData));
        }
예제 #24
0
        public async Task Create_WithNonExistentProductType_ShouldThrowArgumentNullException()
        {
            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            SeedData(context);
            this.productService = new ProductService(context);

            var testProductService = new ProductServiceModel
            {
                Name           = "Pesho",
                Price          = 5,
                ManufacturedOn = DateTime.UtcNow,
                Picture        = "src/res/default.png",
                ProductType    = new ProductTypeServiceModel
                {
                    Name = "asdasda",
                }
            };

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.productService.Create(testProductService));
        }
예제 #25
0
        public async Task Create_WithNonExistentProductType_ShouldThrowArgumentNullException()
        {
            string errorMessagePrefix = "ProductService Create() method does not work properly.";

            var context = StopifyDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.productService = new ProductService(context);

            ProductServiceModel testProduct = new ProductServiceModel
            {
                Name           = "Pesho",
                Price          = 5,
                ManufacturedOn = DateTime.UtcNow,
                Picture        = "src/res/default.png",
                ProductType    = new ProductTypeServiceModel
                {
                    Name = "asdasdasd"
                }
            };

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.productService.Create(testProduct));
        }