public async Task GetList_FilterIsNotContainInDatabase_ReturnError() { // ===== Arrange ===== var dbName = Guid.NewGuid().ToString(); var context = BuildContext(dbName); var mapper = BuildMap(); var httpContext = new Mock <IHttpContextAccessor>(); var http = new DefaultHttpContext(); httpContext.Setup(_ => _.HttpContext).Returns(http); await Generate_ProductGroup_Data(context, mapper, httpContext.Object); var actContext = BuildContext(dbName); // ===== Act ===== var service = new ProductGroupServices(actContext, mapper, httpContext.Object); var result = await service.GetList(Guid.NewGuid().ToString()); // ===== Assert ===== // Result : Used filter that not contain in database // Expected Exception }
public async Task GetList_NoData_ReturnError() { // Arrange var dbName = Guid.NewGuid().ToString(); var context = BuildContext(dbName); var mapper = BuildMap(); var httpContext = new Mock <IHttpContextAccessor>(); var http = new DefaultHttpContext(); // var fakeTenantId = "abcd"; // context.Request.Headers["Tenant-ID"] = fakeTenantId; httpContext.Setup(_ => _.HttpContext).Returns(http); // Act var service = new ProductGroupServices(context, mapper, httpContext.Object); var result = await service.GetList("Group"); // Assert // Filter is presented, but there is not have data. // Expected Exception }
public async Task GetList_HaveDataAndFilter_ReturnFilteredListOfProductGroup() { // ===== Arrange ===== var dbName = Guid.NewGuid().ToString(); var context = BuildContext(dbName); var mapper = BuildMap(); var httpContext = new Mock <IHttpContextAccessor>(); var http = new DefaultHttpContext(); httpContext.Setup(_ => _.HttpContext).Returns(http); await Generate_ProductGroup_Data(context, mapper, httpContext.Object); var actContext = BuildContext(dbName); var result1 = new ServiceResponse <List <ProductGroupDTO> >(); var result2 = new ServiceResponse <List <ProductGroupDTO> >(); var result3 = new ServiceResponse <List <ProductGroupDTO> >(); bool expectEx1 = false; bool expectEx2 = false; bool expectEx3 = false; // ===== Act ===== var service = new ProductGroupServices(actContext, mapper, httpContext.Object); try { result1 = await service.GetList("Group"); } catch (Exception) { expectEx1 = true; throw; } try { result2 = await service.GetList("Group 3"); } catch (Exception) { expectEx2 = true; throw; } try { result3 = await service.GetList(Guid.NewGuid().ToString()); } catch (InvalidOperationException) { expectEx3 = true; } catch (Exception) { expectEx3 = true; throw; } // ===== Assert ===== // Result 1 : Filter is presented, And serach for "Group" Assert.IsFalse(expectEx1); Assert.IsTrue(result1.IsSuccess); Assert.AreEqual(result1.Data.Count, 5); Assert.IsTrue(result1.Data[0].Name.Contains("Group")); Assert.IsTrue(result1.Data[2].Name.Contains("Group")); // Result 2 : Filter is presented, And serach for "Group 3" Assert.IsFalse(expectEx2); Assert.IsTrue(result2.IsSuccess); Assert.AreEqual(result2.Data.Count, 1); Assert.IsTrue(result2.Data[0].Name.Contains("Group 3")); // Result 3 : Filter is presented, And serach for Random value that not exist in the data Assert.IsTrue(expectEx3); Assert.IsNull(result3.Data); }