public void DeleteMailingGroup_Test() { var options = new DbContextOptionsBuilder <CnTaskContext>() .UseInMemoryDatabase(databaseName: "TESTS") .Options; var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(profile: new AutoMapperProfile()); }); using (var context = new CnTaskContext(options)) { context .MailingGroups .Add(new MailingGroup() { Id = Guid.Parse("9F3D8AA5-2B42-469E-AF30-1BC95F388994"), Name = "Test", Receivers = new string[] { "Test" }, }); context.SaveChanges(); } using (var context = new CnTaskContext(options)) { var mapper = new Mapper(mappingConfig); var service = new MailingGroupService(context, mapper); Task.FromResult(service.DeleteMailingGroup(Guid.Parse("9F3D8AA5-2B42-469E-AF30-1BC95F388994"))); } using (var context = new CnTaskContext(options)) { Assert.AreEqual(true, context.MailingGroups.FirstOrDefault(x => x.Id == Guid.Parse("9F3D8AA5-2B42-469E-AF30-1BC95F388994")).IsDeleted); } }
public void EditMailingGroup_Test() { var options = new DbContextOptionsBuilder <CnTaskContext>() .UseInMemoryDatabase(databaseName: "TESTS") .Options; var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(profile: new AutoMapperProfile()); }); using (var context = new CnTaskContext(options)) { context .MailingGroups .Add(new MailingGroup() { Id = Guid.Parse("73FF6568-9C1F-4530-BA15-66463F271084"), Name = "Before Test", Receivers = new string[] { "*****@*****.**" }, }); context.SaveChanges(); } using (var context = new CnTaskContext(options)) { var mapper = new Mapper(mappingConfig); var service = new MailingGroupService(context, mapper); Task.FromResult(service.EditMailingGroup(new MailingGroupUpdateModel() { Id = Guid.Parse("73FF6568-9C1F-4530-BA15-66463F271084"), Name = "After Test", Receivers = new string[] { "*****@*****.**" }, })); } using (var context = new CnTaskContext(options)) { Assert.AreEqual("After Test", context.MailingGroups.FirstOrDefault(x => x.Id == Guid.Parse("73FF6568-9C1F-4530-BA15-66463F271084")).Name); Assert.AreEqual("*****@*****.**", context.MailingGroups.FirstOrDefault(x => x.Id == Guid.Parse("73FF6568-9C1F-4530-BA15-66463F271084")).Receivers.FirstOrDefault()); } }