public void Update_Address() { // Arrange var helper = new TestHelper(); var user = PrincipalHelper.CreateForPermission(Permissions.SystemAdmin); var address = EntityHelper.CreateAddress(1, "1234 Street", null, "V9C9C9"); helper.CreatePimsContext(user, true).AddAndSaveChanges(address); var service = helper.CreateService <AddressService>(user); var updateAddress = EntityHelper.CreateAddress(1, "1234 Street", null, "V9C9C9"); var newName = "1234 Updated Street"; updateAddress.Address1 = newName; // Act service.Update(updateAddress); // Assert address.Address1.Should().Be(newName); var context = helper.GetService <PimsContext>(); // Assert.Equal(EntityState.Modified, context.Entry(address).State); }
public void Update_Address_KeyNotFound() { // Arrange var helper = new TestHelper(); var user = PrincipalHelper.CreateForPermission(); var address = EntityHelper.CreateAddress(1, "1234 Street", null, "V9C9C9"); helper.CreatePimsContext(user, true); var service = helper.CreateService <AddressService>(user); var context = helper.GetService <PimsContext>(); // Act // Assert Assert.Throws <KeyNotFoundException>(() => service.Update(address)); }
public void Update_Address_ThrowIfNull() { // Arrange var helper = new TestHelper(); var user = PrincipalHelper.CreateForPermission(); var address = EntityHelper.CreateAddress(1, "1234 Street", null, "V9C9C9"); helper.CreatePimsContext(user, true).AddAndSaveChanges(address); var service = helper.CreateService <AddressService>(user); var context = helper.GetService <PimsContext>(); // Act // Assert Assert.Throws <ArgumentNullException>(() => service.Update(null)); }
public void Remove_Address() { // Arrange var helper = new TestHelper(); var user = PrincipalHelper .CreateForPermission(Permissions.SystemAdmin, Permissions.AdminRoles); var address = EntityHelper.CreateAddress(1, "1234 Street", null, "V9C9C9"); helper.CreatePimsContext(user, true).AddAndSaveChanges(address); var service = helper.CreateService <AddressService>(user); var context = helper.GetService <PimsContext>(); // Act service.Remove(address); // Assert Assert.Equal(EntityState.Detached, context.Entry(address).State); }