public async Task TestLocalizationMapping2() { //Arrange using (var contextFactory = new SharedSqliteInMemoryContextFactory <LocalizationContext>()) { //Act using (var ctx = contextFactory.ConstructContext()) { var recs = await ctx.Translations.ToListAsync(); //Assert Assert.IsNotNull(recs, "should be 5 records"); Assert.IsInstanceOfType(recs, typeof(List <LocalizationValueEntity>), "Should be true"); Assert.AreEqual(5, recs.Count, "Should be 5 records"); } using (var ctx = contextFactory.ConstructContext()) { ctx.Translations.Add(new LocalizationValueEntity { KeyText = "Sample", KeyCultureId = 1, TranslationCultureId = 2, TranslationText = "Muestra" }); var ct = await ctx.SaveChangesAsync(true); //Assert Assert.AreEqual(1, ct, "Should have saved 1 record."); } using (var ctx = contextFactory.ConstructContext()) { var recs2 = await ctx.Translations.ToListAsync(); //Assert Assert.IsNotNull(recs2, "should be 6 records"); Assert.IsInstanceOfType(recs2, typeof(List <LocalizationValueEntity>), "Should be true"); Assert.AreEqual(6, recs2.Count, "Should be 6 records now"); } } }
public async Task SubmitFormTest2() { //Arrange using (var dirCtxFactory = new SharedSqliteInMemoryContextFactory <DirectoryContext>()) using (var logCtxFactory = new SharedSqliteInMemoryContextFactory <LogContext>()) using (var logCtx = logCtxFactory.ConstructContext()) { await logCtx.Database.ExecuteSqlCommandAsync("delete from detail"); await logCtx.Database.ExecuteSqlCommandAsync("delete from header"); var manager = FactoryManager(null, logCtxFactory, dirCtxFactory); var request = new SubmisionDto { FamilyName = "testerson", AdultOneFirstName = "test", HomePhone = new PhoneDto { PhoneType = PhoneType.Home, Number = "6365555555" }, HomeAddress = new AddressDto { Street = "123 Main", City = "Hometown", Zip = "90210", AddressType = AddressType.Home, State = new StateDto { Abbreviation = "GH" } }, }; //Act var result = await manager.StoreSubmision(request); //Assert Assert.IsNotNull(result, "should always respond."); Assert.AreEqual(ResultType.Exception, result.Type, "Should succeed"); Assert.AreEqual("Could not match state: GH", result.Message, "Should be equal"); Assert.AreEqual(1, logCtx.LogHeaders.Count(), "Should be a msg logged after this"); Assert.AreEqual(2, logCtx.LogDetails.Count(), "Should be two details logged after this"); } }
public async Task TestLoggingMapping2() { //Arrange using (var contextFactory = new SharedSqliteInMemoryContextFactory <LogContext>()) { //Act using (var ctx = contextFactory.ConstructContext()) { var recs = await ctx.LogHeaders .Include(e => e.Details) .ToListAsync(); var rec = recs.FirstOrDefault(); //Assert Assert.IsNotNull(recs, "should be 1 record"); Assert.AreEqual(1, recs.Count, "should be 1 record"); Assert.IsInstanceOfType(recs, typeof(List <LogHeaderEntity>), "Should be equal"); Assert.IsNotNull(rec, "should be 1 record"); Assert.IsInstanceOfType(rec, typeof(LogHeaderEntity), "Should be equal"); Assert.AreEqual(1, rec.Id, "Should be record #1"); Assert.IsNotNull(rec.Details, "should be 2 records"); Assert.AreEqual(2, rec.Details.Count, "should be 2 records"); Assert.IsInstanceOfType(rec.Details, typeof(ICollection <LogDetailEntity>), "Should be equal"); } //Act using (var ctx = contextFactory.ConstructContext()) { await ctx.LogHeaders.AddAsync(new LogHeaderEntity { Level = 2, Details = new List <LogDetailEntity> { new LogDetailEntity { EventType = 4, EventText = "Sample Info Msg" } } }); var ct = await ctx.SaveChangesAsync(true); //Assert Assert.AreEqual(2, ct, "Should have added 2 records"); } //Act using (var ctx = contextFactory.ConstructContext()) { var recs = await ctx.LogHeaders .Include(e => e.Details) .ToListAsync(); var rec = recs.LastOrDefault(); //Assert Assert.IsNotNull(recs, "should be 2 records"); Assert.AreEqual(2, recs.Count, "should be 2 records"); Assert.IsInstanceOfType(recs, typeof(List <LogHeaderEntity>), "Should be equal"); Assert.IsNotNull(rec, "should be 1 record"); Assert.IsInstanceOfType(rec, typeof(LogHeaderEntity), "Should be equal"); Assert.AreEqual(2, rec.Id, "Should be record #2"); Assert.IsNotNull(rec.Details, "should be 1 record"); Assert.AreEqual(1, rec.Details.Count, "should be 1 record"); Assert.IsInstanceOfType(rec.Details, typeof(ICollection <LogDetailEntity>), "Should be equal"); } } }
public async Task TestDirectoryMapping2() { //Arrange using (var contextFactory = new SharedSqliteInMemoryContextFactory <DirectoryContext>()) { //Act using (var ctx = contextFactory.ConstructContext()) { var recs = await ctx.Submisions .Include(e => e.HomeAddress) .ThenInclude(add => add.State) .Include(e => e.HomePhone) .Include(e => e.AdultTwoMobilePhone) .Include(e => e.AdultTwoMobilePhone) .Include(e => e.AdultOneEmail) .Include(e => e.AdultTwoEmail) .ToListAsync(); var rec = recs.FirstOrDefault(); //Assert Assert.IsNotNull(recs, "should be 1 record"); Assert.IsInstanceOfType(recs, typeof(List <SubmisionEntitiy>), "Should be true"); Assert.AreEqual(1, recs.Count, "should be 1 record"); Assert.IsNotNull(rec, "should be 1 record"); Assert.IsInstanceOfType(rec, typeof(SubmisionEntitiy), "Should be true"); Assert.AreEqual(1, rec.Id, "Should be record #1"); Assert.IsNotNull(rec.HomeAddress, "Should load this child table"); Assert.IsNotNull(rec.HomeAddress.State, "Should load this child table"); Assert.IsNotNull(rec.HomePhone, "Should load this child table"); Assert.IsNotNull(rec.AdultTwoMobilePhone, "Should load this child table"); Assert.IsNotNull(rec.AdultTwoMobilePhone, "Should load this child table"); Assert.IsNotNull(rec.AdultOneEmail, "Should load this child table"); Assert.IsNotNull(rec.AdultTwoEmail, "Should load this child table"); } //Act using (var ctx = contextFactory.ConstructContext()) { await ctx.Submisions.AddAsync(new SubmisionEntitiy { AdultOneFirstName = "MoarTest", AdultTwoFirstName = "YesTest", FamilyName = "Testington", OtherFamily = "Test", PublishAddress = true, PublishPhone = false, AdultOneMobilePhone = new PhoneEntity { TypeId = 2, Number = "405-555-4321" }, AdultTwoMobilePhone = new PhoneEntity { TypeId = 2, Number = "405-555-5678" }, HomePhone = new PhoneEntity { TypeId = 1, Number = "405-555-1234" }, AdultTwoEmail = new EmailAddressEntity { EmailType = 1, Email = "*****@*****.**" }, AdultOneEmail = new EmailAddressEntity { EmailType = 1, Email = "*****@*****.**" }, HomeAddress = new AddressEntity { StateId = 1, City = "Oklahoma City", Street = "3233 Sw 94th St.", Zip = "73159" } }); var ct = await ctx.SaveChangesAsync(true); //Assert Assert.AreEqual(7, ct, "Seven classes means 7 records. Would be 8 if we created a new state as well."); } //Act using (var ctx = contextFactory.ConstructContext()) { var recs = await ctx.Submisions .Include(e => e.HomeAddress) .ThenInclude(add => add.State) .Include(e => e.HomePhone) .Include(e => e.AdultTwoMobilePhone) .Include(e => e.AdultTwoMobilePhone) .Include(e => e.AdultOneEmail) .Include(e => e.AdultTwoEmail) .OrderBy(e => e.Id) .ToListAsync(); var rec = recs.LastOrDefault(); //Assert Assert.IsNotNull(recs, "should be 2 records"); Assert.IsInstanceOfType(recs, typeof(List <SubmisionEntitiy>), "Should be true"); Assert.AreEqual(2, recs.Count, "should be 2 records"); Assert.IsNotNull(rec, "should be 1 record"); Assert.IsInstanceOfType(rec, typeof(SubmisionEntitiy), "Should be true"); Assert.AreEqual(2, rec.Id, "Should be record #2"); Assert.IsNotNull(rec.HomeAddress, "Should load this child table"); Assert.IsNotNull(rec.HomeAddress.State, "Should load this child table"); Assert.IsNotNull(rec.HomePhone, "Should load this child table"); Assert.IsNotNull(rec.AdultTwoMobilePhone, "Should load this child table"); Assert.IsNotNull(rec.AdultTwoMobilePhone, "Should load this child table"); Assert.IsNotNull(rec.AdultOneEmail, "Should load this child table"); Assert.IsNotNull(rec.AdultTwoEmail, "Should load this child table"); } } }