public async Task CanCreateNonObligatedWeeeEntry(bool dcf) { using (DatabaseWrapper database = new DatabaseWrapper()) { // Arrange var context = database.WeeeContext; var name = "Test Name" + Guid.NewGuid(); var tradingName = "Test Trading Name" + Guid.NewGuid(); const string crn = "ABC12345"; var organisation = Organisation.CreateRegisteredCompany(name, crn, tradingName); context.Organisations.Add(organisation); await context.SaveChangesAsync(); var quarter = new Quarter(2019, QuarterType.Q1); var aatfReturn = new Return(organisation, quarter, database.Model.AspNetUsers.First().Id, FacilityType.Aatf); var categoryValues = new List <NonObligatedValue>(); foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>()) { categoryValues.Add(new NonObligatedValue((int)category, (int)category, dcf, Guid.NewGuid())); } var nonObligatedRequest = new AddNonObligated { ReturnId = aatfReturn.Id, OrganisationId = organisation.Id, CategoryValues = categoryValues }; var nonObligatedWee = new List <NonObligatedWeee>(); foreach (var categoryValue in nonObligatedRequest.CategoryValues) { nonObligatedWee.Add(new NonObligatedWeee(aatfReturn, categoryValue.CategoryId, categoryValue.Dcf, categoryValue.Tonnage)); } var dataAccess = new NonObligatedDataAccess(database.WeeeContext); // Act await dataAccess.InsertNonObligatedWeee(aatfReturn.Id, nonObligatedWee); // Assert var thisTestNonObligatedWeeeArray = context.NonObligatedWeee.Where(o => o.ReturnId == aatfReturn.Id).ToArray(); Assert.NotNull(thisTestNonObligatedWeeeArray); Assert.NotEmpty(thisTestNonObligatedWeeeArray); foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>()) { var foundCategory = thisTestNonObligatedWeeeArray.FirstOrDefault(o => o.CategoryId == (int)category); foundCategory.Should().NotBeNull(); var indexNum = (int)category - 1; Assert.Equal(foundCategory.Dcf, nonObligatedWee[indexNum].Dcf); Assert.Equal(foundCategory.Tonnage, nonObligatedWee[indexNum].Tonnage); Assert.Equal(foundCategory.ReturnId, nonObligatedWee[indexNum].ReturnId); } } }
public async Task FetchNonObligatedWeeeForReturn_ReturnedListShouldContainAllTonnagesFromRequest(bool dcf) { using (var database = new DatabaseWrapper()) { var helper = new ModelHelper(database.Model); var domainHelper = new DomainHelper(database.WeeeContext); var context = A.Fake <WeeeContext>(); var @return = CreateReturn(database); var returnDataAccess = new ReturnDataAccess(database.WeeeContext); await returnDataAccess.Submit(@return); var categoryValues = new List <NonObligatedValue>(); foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>()) { categoryValues.Add(new NonObligatedValue((int)category, (int)category, dcf, Guid.NewGuid())); } var nonObligatedRequest = new AddNonObligated() { ReturnId = @return.Id, OrganisationId = @return.Organisation.Id, Dcf = dcf, CategoryValues = categoryValues }; var nonObligatedWee = new List <NonObligatedWeee>(); foreach (var categoryValue in nonObligatedRequest.CategoryValues) { nonObligatedWee.Add(new NonObligatedWeee(@return, categoryValue.CategoryId, dcf, categoryValue.Tonnage)); } var nonObDataAccess = new NonObligatedDataAccess(database.WeeeContext); await nonObDataAccess.InsertNonObligatedWeee(@return.Id, nonObligatedWee); var dataAccess = new NonObligatedDataAccess(database.WeeeContext); var tonnageList = await dataAccess.FetchNonObligatedWeeeForReturn(@return.Id, dcf); foreach (var category in nonObligatedWee) { tonnageList.Should().Contain(category.Tonnage); } } }
private static async Task CreateNonObligatedWeee(NonObligatedDataAccess dataAccess, Return @return) { var nonObligatedWee = new List <NonObligatedWeee>(); foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>()) { nonObligatedWee.Add(new NonObligatedWeee(@return, (int)category, false, (decimal?)category)); } foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>()) { nonObligatedWee.Add(new NonObligatedWeee(@return, (int)category, true, (decimal?)category)); } await dataAccess.InsertNonObligatedWeee(@return.Id, nonObligatedWee); }