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."); } }
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); }
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); }
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."); } }
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."); }
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."); } }
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); }
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")); }
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); }
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)); }
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)); }
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")); }
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); }
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."); }
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); }
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); }
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); }
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)); }
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); }
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."); }
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); }
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); }
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)); }
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)); }
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)); }