public void RoundTrip_Properties(string propertyName, object value) { Delta <DeltaModel> delta = new Delta <DeltaModel>(); Type propertyType; Assert.True(delta.TryGetPropertyType(propertyName, out propertyType)); Assert.True(delta.TrySetPropertyValue(propertyName, value)); object retrievedValue; delta.TryGetPropertyValue(propertyName, out retrievedValue); Assert.Equal(value, retrievedValue); }
public IHttpActionResult Patch([FromODataUri] int key, Delta<Product> patch) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Delta<V2VM.Product> v2Patch = new Delta<V2VM.Product>(); foreach (string name in patch.GetChangedPropertyNames()) { object value; if (patch.TryGetPropertyValue(name, out value)) { v2Patch.TrySetPropertyValue(name, value); } } var v2Product = _repository.Patch((long)key, v2Patch, Request); return Updated(Mapper.Map<Product>(v2Product)); }
public void Put_DoesNotClear_NonUpdatableProperties() { // Arrange string expectedString = "hello, world"; int expectedInt = 24; var delta = new Delta <Base>(typeof(Base), new[] { "BaseInt" }); delta.TrySetPropertyValue("BaseInt", expectedInt); Base entity = new Base { BaseInt = 42, BaseString = expectedString }; // Act delta.Put(entity); // Assert Assert.Equal(expectedInt, entity.BaseInt); Assert.Equal(expectedString, entity.BaseString); }
public void PatchUpdateClient() { var controller = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test", contactPersonName = "Patch Client" }; var addedClient = controller.PostClient(newClient).Content.ReadAsAsync<Client>().Result; Delta<Client> client = new Delta<Client>(); client.TrySetPropertyValue("streetAddress", "Danderydsgatan 28"); controller.PatchClient(addedClient.id, client); var gottenPerformer = controller.GetClient(addedClient.id); Assert.IsTrue(gottenPerformer.contactPersonName == newClient.contactPersonName); Assert.IsTrue(gottenPerformer.streetAddress == "Danderydsgatan 28"); }
public async Task Patch_NotExistingEntity() { using (IDataContext context = GetDataContext()) using (IRaceDataUnitOfWork uow = new RaceDataUnitOfWork(context, new Logger())) { //Arrange MeetingsController controller = new MeetingsController(uow); await SetupData(controller, uow); // Expected Meeting expected = mockmeetings.ElementAt(1); Delta<Meeting> delta = new Delta<Meeting>(typeof(Meeting)); delta.TrySetPropertyValue("VenueName", expected.VenueName + " Patched"); //Act IHttpActionResult response = await controller.Patch(1, delta); // Assert Assert.IsNotNull(response, "A response equal to null is unexpected!"); Assert.IsInstanceOfType(response, typeof(NotFoundResult)); } }
public async Task Patch() { using (IDataContext context = GetDataContext()) using (IRaceDataUnitOfWork uow = new RaceDataUnitOfWork(context, new Logger())) { //Arrange MeetingsController controller = new MeetingsController(uow); await SetupData(controller, uow, false); // Expected Meeting expected = mockmeetings.ElementAt(0); Delta<Meeting> delta = new Delta<Meeting>(typeof(Meeting)); delta.TrySetPropertyValue("VenueName", expected.VenueName + " Patched"); //Act IHttpActionResult post_response = await controller.Post(mockmeetings.ElementAt(0)); CreatedNegotiatedContentResult<Meeting> post_actual = post_response as CreatedNegotiatedContentResult<Meeting>; // Assert Assert.IsNotNull(post_actual, "A response equal to null is unexpected!"); //Act IHttpActionResult response = await controller.Patch(post_actual.Content.Id, delta); UpdatedODataResult<Meeting> actual = response as UpdatedODataResult<Meeting>; // Assert Assert.IsNotNull(actual, "A response equal to null is unexpected!"); Assert.AreEqual(actual.Entity.VenueName, expected.VenueName); Assert.AreEqual(actual.Entity.NumberOfRaces, expected.NumberOfRaces); Assert.AreEqual(actual.Entity.Coverages.Count(), expected.Coverages.Count()); Assert.AreEqual(actual.Entity.RaceStarts.Count(), expected.RaceStarts.Count()); } }
public void PatchUpdateAssignment() { var clientController = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test Patch Assignment" }; clientController.PostClient(newClient); var assignmentController = Controllers.GetAssignmentController(); var newAssignment = new Assignment() { description = "Test Patch Assignment" }; var addedAssignment = assignmentController.PostAssignment(newAssignment).Content.ReadAsAsync<Assignment>().Result; Delta<Assignment> assignment = new Delta<Assignment>(); assignment.TrySetPropertyValue("description", "Test Patch Assignment 2"); assignmentController.PatchAssignment(addedAssignment.id, assignment); var gottenAssignment = assignmentController.GetAssignment(addedAssignment.id); Assert.IsTrue(gottenAssignment.description == newAssignment.description); }
public void PatchUpdatePerformer() { var controller = Controllers.GetPerformerController(); var newPerformer = new Performer() { firstName = "Test", lastName = "Patch Performer", birthDate = DateTime.Now }; var addedPerformer = controller.PostPerformer(newPerformer).Content.ReadAsAsync<Performer>().Result; Delta<Performer> performer = new Delta<Performer>(); performer.TrySetPropertyValue("country", "Sweden"); controller.PatchPerformer(addedPerformer.id, performer); var gottenPerformer = controller.GetPerformer(addedPerformer.id); Assert.IsTrue(gottenPerformer.lastName == newPerformer.lastName); Assert.IsTrue(gottenPerformer.country == "Sweden"); }