public async Task ModelIsCreated() { var context = ServiceProvider.GetService<AllReadyContext>(); var sut = new EditCampaignCommandHandler(context); var actual = await sut.Handle(new EditCampaignCommand { Campaign = new CampaignSummaryModel { TimeZoneId = "Eastern Standard Time" } }); Assert.NotEqual(0, actual); }
public void ExistingCampaign() { var context = ServiceProvider.GetService<AllReadyContext>(); Organization htb = new Organization() { Name = "Humanitarian Toolbox", LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png", WebUrl = "http://www.htbox.org", Campaigns = new List<Campaign>() }; Campaign firePrev = new Campaign() { Name = "Neighborhood Fire Prevention Days", ManagingOrganization = htb, TimeZoneId = "Eastern Standard Time" }; htb.Campaigns.Add(firePrev); context.Organizations.Add(htb); context.SaveChanges(); const string NEW_NAME = "Some new name value"; var startDate = new DateTime(2014, 12, 10); var endDate = new DateTime(2015, 7, 3); var vm = new CampaignSummaryModel { Description = firePrev.Description, EndDate = endDate, FullDescription = firePrev.FullDescription, StartDate = startDate, Id = firePrev.Id, ImageUrl = firePrev.ImageUrl, Name = NEW_NAME, OrganizationId = firePrev.ManagingOrganizationId, OrganizationName = firePrev.ManagingOrganization.Name, TimeZoneId = "Eastern Standard Time" }; var query = new EditCampaignCommand { Campaign = vm }; var handler = new EditCampaignCommandHandler(context); var result = handler.Handle(query); Assert.Equal(1, result); // should get back the Campaign id var data = context.Campaigns.Single(_ => _.Id == 1); Assert.Equal(NEW_NAME, data.Name); Assert.Equal(2014, data.StartDateTime.Year); Assert.Equal(12, data.StartDateTime.Month); Assert.Equal(10, data.StartDateTime.Day); Assert.Equal(00, data.StartDateTime.Hour); Assert.Equal(00, data.StartDateTime.Minute); Assert.Equal(-5, data.StartDateTime.Offset.TotalHours); Assert.Equal(2015, data.EndDateTime.Year); Assert.Equal(7, data.EndDateTime.Month); Assert.Equal(3, data.EndDateTime.Day); Assert.Equal(23, data.EndDateTime.Hour); Assert.Equal(59, data.EndDateTime.Minute); Assert.Equal(-4, data.EndDateTime.Offset.TotalHours); }
public void CampaignDoesNotExist() { var context = ServiceProvider.GetService<AllReadyContext>(); var vm = new CampaignSummaryModel(); var query = new EditCampaignCommand { Campaign = vm }; var handler = new EditCampaignCommandHandler(context); var result = handler.Handle(query); Assert.True(result > 0); var data = context.Campaigns.Count(_ => _.Id == result); Assert.True(data == 1); }
public async Task AddNewCampaign() { // Arrange var handler = new EditCampaignCommandHandler(Context); var newCampaign = new CampaignSummaryModel { Name = "New", Description = "Desc", TimeZoneId ="UTC" }; // Act var result = await handler.Handle(new EditCampaignCommand { Campaign = newCampaign }); // Assert Assert.Equal(5, Context.Campaigns.Count()); Assert.True(result > 0); }
public async Task CampaignDoesNotExist() { var context = ServiceProvider.GetService<AllReadyContext>(); var vm = new CampaignSummaryModel { TimeZoneId = "Eastern Standard Time" }; var query = new EditCampaignCommand { Campaign = vm }; var handler = new EditCampaignCommandHandler(context); var result = await handler.Handle(query); Assert.True(result > 0); var data = context.Campaigns.Count(_ => _.Id == result); Assert.True(data == 1); }
public async Task UpdatingExistingCampaign_UpdatesAllCoreProperties() { CampaignsHandlerTestHelper.LoadCampaignssHandlerTestData(Context); // Arrange const string name = "New Name"; const string desc = "New Desc"; const string fullDesc = "New Full Desc"; const string timezoneId = "GMT Standard Time"; var startDate = DateTime.Now; var endDate = DateTime.Now.AddDays(30); const int org = 2; var handler = new EditCampaignCommandHandler(Context, Mock.Of<IConvertDateTimeOffset>()); var updatedCampaign = new CampaignSummaryViewModel { Id = 2, Name = name, Description = desc, FullDescription = fullDesc, TimeZoneId = timezoneId, StartDate = startDate, EndDate = endDate, OrganizationId = org, }; //Act var result = await handler.Handle(new EditCampaignCommand { Campaign = updatedCampaign }); var savedCampaign = Context.Campaigns.SingleOrDefault(s => s.Id == 2); // Assert Assert.Equal(4, Context.Campaigns.Count()); Assert.Equal(2, result); Assert.Equal(name, savedCampaign.Name); Assert.Equal(desc, savedCampaign.Description); Assert.Equal(fullDesc, savedCampaign.FullDescription); Assert.Equal(timezoneId, savedCampaign.TimeZoneId); Assert.NotEqual(startDate.Date, new DateTime()); // We're not testing the date logic in this test, only that a datetime value is saved Assert.NotEqual(endDate.Date, new DateTime()); // We're not testing the date logic in this test, only that a datetime value is saved Assert.Equal(org, savedCampaign.ManagingOrganizationId); }
public void ExistingCampaign() { var context = ServiceProvider.GetService<AllReadyContext>(); Tenant htb = new Tenant() { Name = "Humanitarian Toolbox", LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png", WebUrl = "http://www.htbox.org", Campaigns = new List<Campaign>() }; Campaign firePrev = new Campaign() { Name = "Neighborhood Fire Prevention Days", ManagingTenant = htb }; htb.Campaigns.Add(firePrev); context.Tenants.Add(htb); context.SaveChanges(); const string NEW_NAME = "Some new name value"; var vm = new CampaignSummaryModel { Description = firePrev.Description, EndDate = firePrev.EndDateTimeUtc, FullDescription = firePrev.FullDescription, StartDate = firePrev.StartDateTimeUtc, Id = firePrev.Id, ImageUrl = firePrev.ImageUrl, Name = NEW_NAME, TenantId = firePrev.ManagingTenantId, TenantName = firePrev.ManagingTenant.Name }; var query = new EditCampaignCommand { Campaign = vm }; var handler = new EditCampaignCommandHandler(context); var result = handler.Handle(query); Assert.Equal(1, result); // should get back the Campaign id var data = context.Campaigns.Single(_ => _.Id == 1); Assert.Equal(NEW_NAME, data.Name); }
public async Task UpdatingExistingCampaignWithNoPriorContactAddsContactWithAllProperties() { // Arrange var name = "New Name"; var desc = "New Desc"; var org = 2; var contactEmail = "*****@*****.**"; var firstname = "John"; var lastname = "Doe"; var telephone = "01323 111111"; var handler = new EditCampaignCommandHandler(Context); var updatedCampaign = new CampaignSummaryModel { Id = 2, Name = name, Description = desc, OrganizationId = org, TimeZoneId = "GMT Standard Time", PrimaryContactEmail = contactEmail, PrimaryContactFirstName = firstname, PrimaryContactLastName = lastname, PrimaryContactPhoneNumber = telephone }; // Act await handler.Handle(new EditCampaignCommand { Campaign = updatedCampaign }); var newContact = Context.Contacts.OrderBy(c => c.Id).LastOrDefault(); // Assert Assert.Equal(2, Context.CampaignContacts.Count()); Assert.Equal(2, Context.Contacts.Count()); Assert.NotNull(newContact); Assert.Equal(contactEmail, newContact.Email); Assert.Equal(firstname, newContact.FirstName); Assert.Equal(lastname, newContact.LastName); Assert.Equal(telephone, newContact.PhoneNumber); }
public async Task UpdatingExistingCampaign_UpdatesLocationWithAllProperties() { CampaignsHandlerTestHelper.LoadCampaignssHandlerTestData(Context); // Arrange const string name = "New Name"; const string desc = "New Desc"; const int org = 2; const string address1 = "Address 1"; const string address2 = "Address 1"; const string city = "City"; const string state = "State"; const string postcode = "45231"; const string country = "USA"; var handler = new EditCampaignCommandHandler(Context, Mock.Of <IConvertDateTimeOffset>()); var updatedCampaign = new CampaignSummaryViewModel { Id = 2, Name = name, Description = desc, OrganizationId = org, TimeZoneId = "GMT Standard Time", Location = new LocationEditViewModel { Address1 = address1, Address2 = address2, City = city, State = state, PostalCode = postcode } }; // Act await handler.Handle(new EditCampaignCommand { Campaign = updatedCampaign }); var savedCampaign = Context.Campaigns.SingleOrDefault(s => s.Id == 2); // Assert Assert.Equal(address1, savedCampaign.Location.Address1); Assert.Equal(address2, savedCampaign.Location.Address2); Assert.Equal(city, savedCampaign.Location.City); Assert.Equal(state, savedCampaign.Location.State); Assert.Equal(postcode, savedCampaign.Location.PostalCode); Assert.Equal(country, savedCampaign.Location.Country); }
public async Task WhenCampaignDoesNotExist_NewCampaignIsAddedToTheDatabase() { const string name = "Test campaign"; // arrange var vm = new CampaignSummaryViewModel { Name = name }; var sut = new EditCampaignCommandHandler(Context, Mock.Of<IConvertDateTimeOffset>()); var query = new EditCampaignCommand { Campaign = vm }; // act var result = await sut.Handle(query); var data = Context.Campaigns.Single(rec => rec.Id == result); // assert result.ShouldBe(1); // Since no prior records ID should be 1 data.Name.ShouldBe(name); // The name stored in the DB should match the value passed into the command }
public void UpdatingExistingCampaignUpdatesLocationWithAllProperties() { // Arrange var name = "New Name"; var desc = "New Desc"; var org = 2; var address1 = "Address 1"; var address2 = "Address 1"; var city = "City"; var state = "State"; var postcode = "45231"; var country = "USA"; var handler = new EditCampaignCommandHandler(Context); var updatedCampaign = new CampaignSummaryModel { Id = 2, Name = name, Description = desc, OrganizationId = org, TimeZoneId = "GMT Standard Time", Location = new LocationEditModel { Address1 = address1, Address2 = address2, City = city, State = state, PostalCode = postcode } }; // Act var result = handler.Handle(new EditCampaignCommand { Campaign = updatedCampaign }); var savedCampaign = Context.Campaigns.SingleOrDefault(s => s.Id == 2); // Assert Assert.Equal(address1, savedCampaign.Location.Address1); Assert.Equal(address2, savedCampaign.Location.Address2); Assert.Equal(city, savedCampaign.Location.City); Assert.Equal(state, savedCampaign.Location.State); Assert.Equal(postcode, savedCampaign.Location.PostalCode.PostalCode); Assert.Equal(country, savedCampaign.Location.Country); }
public async Task UpdatingExistingCampaignUpdatesAllCoreProperties() { // Arrange var name = "New Name"; var desc = "New Desc"; var fullDesc = "New Full Desc"; var timezoneId = "GMT Standard Time"; var startDate = DateTime.Now; var endDate = DateTime.Now.AddDays(30); var org = 2; var handler = new EditCampaignCommandHandler(Context); var updatedCampaign = new CampaignSummaryModel { Id = 2, Name = name, Description = desc, FullDescription = fullDesc, TimeZoneId = timezoneId, StartDate = startDate, EndDate = endDate, OrganizationId = org, }; // Act var result = await handler.Handle(new EditCampaignCommand { Campaign = updatedCampaign }); var savedCampaign = Context.Campaigns.SingleOrDefault(s => s.Id == 2); // Assert Assert.Equal(4, Context.Campaigns.Count()); Assert.Equal(2, result); Assert.Equal(name, savedCampaign.Name); Assert.Equal(desc, savedCampaign.Description); Assert.Equal(fullDesc, savedCampaign.FullDescription); Assert.Equal(timezoneId, savedCampaign.TimeZoneId); Assert.NotEqual(startDate.Date, new DateTime()); // We're not testing the date logic in this test, only that a datetime value is saved Assert.NotEqual(endDate.Date, new DateTime()); // We're not testing the date logic in this test, only that a datetime value is saved Assert.Equal(org, savedCampaign.ManagingOrganizationId); }
public void UpdatingExistingCampaignUpdatesAllCoreProperties() { // Arrange var name = "New Name"; var desc = "New Desc"; var fullDesc = "New Full Desc"; var timezoneId = "GMT Standard Time"; var startDate = DateTime.Now; var endDate = DateTime.Now.AddDays(30); var org = 2; var handler = new EditCampaignCommandHandler(Context); var updatedCampaign = new CampaignSummaryModel { Id = 2, Name = name, Description = desc, FullDescription = fullDesc, TimeZoneId = timezoneId, StartDate = startDate, EndDate = endDate, OrganizationId = org, }; // Act var result = handler.Handle(new EditCampaignCommand { Campaign = updatedCampaign }); var savedCampaign = Context.Campaigns.SingleOrDefault(s => s.Id == 2); // Assert Assert.Equal(2, Context.Campaigns.Count()); Assert.Equal(2, result); Assert.Equal(name, savedCampaign.Name); Assert.Equal(desc, savedCampaign.Description); Assert.Equal(fullDesc, savedCampaign.FullDescription); Assert.Equal(timezoneId, savedCampaign.TimeZoneId); Assert.NotEqual(startDate.Date, new DateTime()); // We're not testing the date logic in this test, only that a datetime value is saved Assert.NotEqual(endDate.Date, new DateTime()); // We're not testing the date logic in this test, only that a datetime value is saved Assert.Equal(org, savedCampaign.ManagingOrganizationId); }
public async Task WhenCampaignDoesNotExist_NewCampaignIsAddedToTheDatabase() { const string name = "Test campaign"; // arrange var vm = new CampaignSummaryViewModel { Name = name }; var sut = new EditCampaignCommandHandler(Context, Mock.Of <IConvertDateTimeOffset>()); var query = new EditCampaignCommand { Campaign = vm }; // act var result = await sut.Handle(query); var data = Context.Campaigns.Single(rec => rec.Id == result); // assert result.ShouldBe(1); // Since no prior records ID should be 1 data.Name.ShouldBe(name); // The name stored in the DB should match the value passed into the command }
public async Task UpdatingExistingCampaign_UpdatesLocationWithAllProperties() { CampaignsHandlerTestHelper.LoadCampaignssHandlerTestData(Context); // Arrange const string name = "New Name"; const string desc = "New Desc"; const int org = 2; const string address1 = "Address 1"; const string address2 = "Address 1"; const string city = "City"; const string state = "State"; const string postcode = "45231"; const string country = "USA"; var handler = new EditCampaignCommandHandler(Context, Mock.Of<IConvertDateTimeOffset>()); var updatedCampaign = new CampaignSummaryViewModel { Id = 2, Name = name, Description = desc, OrganizationId = org, TimeZoneId = "GMT Standard Time", Location = new LocationEditViewModel { Address1 = address1, Address2 = address2, City = city, State = state, PostalCode = postcode } }; // Act await handler.Handle(new EditCampaignCommand { Campaign = updatedCampaign }); var savedCampaign = Context.Campaigns.SingleOrDefault(s => s.Id == 2); // Assert Assert.Equal(address1, savedCampaign.Location.Address1); Assert.Equal(address2, savedCampaign.Location.Address2); Assert.Equal(city, savedCampaign.Location.City); Assert.Equal(state, savedCampaign.Location.State); Assert.Equal(postcode, savedCampaign.Location.PostalCode); Assert.Equal(country, savedCampaign.Location.Country); }
public async Task ExistingCampaign() { var context = ServiceProvider.GetService <AllReadyContext>(); var htb = new Organization() { Name = "Humanitarian Toolbox", LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png", WebUrl = "http://www.htbox.org", Campaigns = new List <Campaign>() }; var firePrev = new Campaign() { Name = "Neighborhood Fire Prevention Days", ManagingOrganization = htb, TimeZoneId = "Eastern Standard Time" }; htb.Campaigns.Add(firePrev); context.Organizations.Add(htb); context.SaveChanges(); const string NEW_NAME = "Some new name value"; var startDate = new DateTime(2014, 12, 10); var endDate = new DateTime(2015, 7, 3); var vm = new CampaignSummaryModel { Description = firePrev.Description, EndDate = endDate, FullDescription = firePrev.FullDescription, StartDate = startDate, Id = firePrev.Id, ImageUrl = firePrev.ImageUrl, Name = NEW_NAME, OrganizationId = firePrev.ManagingOrganizationId, OrganizationName = firePrev.ManagingOrganization.Name, TimeZoneId = "Eastern Standard Time" }; var query = new EditCampaignCommand { Campaign = vm }; var handler = new EditCampaignCommandHandler(context); var result = await handler.Handle(query); Assert.Equal(1, result); // should get back the Campaign id var data = context.Campaigns.Single(_ => _.Id == 1); Assert.Equal(NEW_NAME, data.Name); Assert.Equal(2014, data.StartDateTime.Year); Assert.Equal(12, data.StartDateTime.Month); Assert.Equal(10, data.StartDateTime.Day); Assert.Equal(00, data.StartDateTime.Hour); Assert.Equal(00, data.StartDateTime.Minute); Assert.Equal(-5, data.StartDateTime.Offset.TotalHours); Assert.Equal(2015, data.EndDateTime.Year); Assert.Equal(7, data.EndDateTime.Month); Assert.Equal(3, data.EndDateTime.Day); Assert.Equal(23, data.EndDateTime.Hour); Assert.Equal(59, data.EndDateTime.Minute); Assert.Equal(-4, data.EndDateTime.Offset.TotalHours); }
public async Task UpdatingExistingCampaignWithNoPriorContactAddsContactWithAllProperties() { // Arrange var name = "New Name"; var desc = "New Desc"; var org = 2; var contactEmail = "*****@*****.**"; var firstname = "John"; var lastname = "Doe"; var telephone = "01323 111111"; var handler = new EditCampaignCommandHandler(Context); var updatedCampaign = new CampaignSummaryModel { Id = 2, Name = name, Description = desc, OrganizationId = org, TimeZoneId = "GMT Standard Time", PrimaryContactEmail = contactEmail, PrimaryContactFirstName =firstname, PrimaryContactLastName = lastname, PrimaryContactPhoneNumber = telephone }; // Act await handler.Handle(new EditCampaignCommand { Campaign = updatedCampaign }); var newContact = Context.Contacts.OrderBy(c=>c.Id).LastOrDefault(); // Assert Assert.Equal(2, Context.CampaignContacts.Count()); Assert.Equal(2, Context.Contacts.Count()); Assert.NotNull(newContact); Assert.Equal(contactEmail, newContact.Email); Assert.Equal(firstname, newContact.FirstName); Assert.Equal(lastname, newContact.LastName); Assert.Equal(telephone, newContact.PhoneNumber); }
public void ModelIsCreated() { var sut = new EditCampaignCommandHandler(Context); int actual = sut.Handle(new EditCampaignCommand {Campaign = new CampaignSummaryModel { TimeZoneId = "Eastern Standard Time" } }); Assert.NotEqual(0, actual); }
public void ModelIsCreated() { var sut = new EditCampaignCommandHandler(Context); int actual = sut.Handle(new EditCampaignCommand {Campaign = new CampaignSummaryModel()}); Assert.NotEqual(0, actual); }