public async Task Discover_product_by_name_expect_two() { var target = new ProductServices(Helper.CreateMemoryUow()); var mockProduct1 = FixturesDto.ProductsBuildOne(); // Bogus doesn't ensure unique names mockProduct1.Name = "Prod1"; await target.CreateAsync(mockProduct1); var mockProduct2 = FixturesDto.ProductsBuildOne(); await target.CreateAsync(mockProduct2); var mockProduct3 = FixturesDto.ProductsBuildOne(); mockProduct3.Name = mockProduct2.Name; await target.CreateAsync(mockProduct3); var result = await target.GetByNameAsync(mockProduct2.Name); Assert.IsNotNull(result); Assert.AreEqual(2, result.Count(), $"Expected two products with name '{ mockProduct2.Name}' to be found!"); Assert.AreEqual(mockProduct2.Name, result.First().Name); }
public async Task Discover_product_by_id() { var target = new ProductServices(Helper.CreateMemoryUow()); var mockProduct1 = FixturesDto.ProductsBuildOne(); await target.CreateAsync(mockProduct1); var mockProduct2 = FixturesDto.ProductsBuildOne(); await target.CreateAsync(mockProduct2); var result = await target.GetByIdAsync(mockProduct2.Id); Assert.IsNotNull(result); Assert.AreEqual(mockProduct2.Id, result.Id); }
public async Task Get_all_products_expected_two() { var target = new ProductServices(Helper.CreateMemoryUow()); var mockProduct1 = FixturesDto.ProductsBuildOne(); await target.CreateAsync(mockProduct1); var mockProduct2 = FixturesDto.ProductsBuildOne(); await target.CreateAsync(mockProduct2); var result = await target.GetAllAsync(); Assert.IsNotNull(result); Assert.AreEqual(2, result.Count(), "Expected two products to be found!"); }
public async Task Delete_product_fail() { var target = new ProductServices(Helper.CreateMemoryUow()); var mockProduct = FixturesDto.ProductsBuildOne(); var result = Task.FromResult(target.CreateAsync(mockProduct)).Result; var newProductId = Guid.NewGuid();; var deleteResult = await target.DeleteByIdAsync(newProductId); Assert.IsFalse(deleteResult); }
public async Task Update_product_success() { var target = new ProductServices(Helper.CreateMemoryUow()); var mockProduct1 = FixturesDto.ProductsBuildOne(); await target.CreateAsync(mockProduct1); var mockProduct2 = FixturesDto.ProductsBuildOne(); await target.CreateAsync(mockProduct2); var mockProduct3 = FixturesDto.ProductsBuildOne(); var prodtoUpdate = await target.CreateAsync(mockProduct3); prodtoUpdate.Name = "UpdatedProd"; var result = await target.UpdateAsync(prodtoUpdate); Assert.IsNotNull(result); Assert.AreEqual(prodtoUpdate.Name, result.Name); Assert.AreNotEqual(mockProduct3.Name, result.Name); }
public void BasicCreateAsyncTest() { var target = new ProductServices(Helper.CreateMemoryUow()); var mockProduct = FixturesDto.ProductsBuildOne(); var result = Task.FromResult(target.CreateAsync(mockProduct)).Result; Assert.IsNull(result.Exception); Assert.IsNotNull(result.Result); // The row version is returned Assert.IsNotNull(result.Result.RowVersion); Assert.IsTrue(result.Result.RowVersion.Length > 0); }
public async Task Update_product_conflict() { var target = new ProductServices(Helper.CreateMemoryUow()); var mockProduct1 = FixturesDto.ProductsBuildOne(); await target.CreateAsync(mockProduct1); var mockProduct2 = FixturesDto.ProductsBuildOne(); await target.CreateAsync(mockProduct2); var mockProduct3 = FixturesDto.ProductsBuildOne(); var prodtoUpdate = await target.CreateAsync(mockProduct3); prodtoUpdate.Name = "UpdatedProd"; // Initial update var result = await target.UpdateAsync(prodtoUpdate); // need to revise prodtoUpdate.Name = "Confict"; var result2 = Task.FromResult(target.UpdateAsync(prodtoUpdate)).Result; Assert.IsNotNull(result2.Exception); Assert.IsInstanceOfType(result2.Exception.InnerException, typeof(System.Data.Entity.Infrastructure.DbUpdateConcurrencyException)); }