Example #1
0
        public void Patch_Should_Not_Update_If_No_PropertiesToMerge()
        {
            var from = new TestModel
            {
                Id               = 2,
                Name             = "New Test",
                Description      = "Updated description",
                ShortDescription = "Updated short description",
                CreatedAt        = new DateTime(2015, 1, 2)
            };
            var to = new TestModel
            {
                Id               = 1,
                Name             = "Test",
                Description      = "This is a test",
                ShortDescription = "Short description",
                CreatedAt        = new DateTime(2015, 1, 1)
            };
            var propertiesToMerge = Enumerable.Empty <string>();

            var result = new PatchExecutor().Patch(from, to, propertiesToMerge);

            Assert.IsTrue(result);
            Assert.AreNotEqual(from.Id, to.Id);
            Assert.AreNotEqual(from.Name, to.Name);
            Assert.AreNotEqual(from.Description, to.Description);
            Assert.AreNotEqual(from.ShortDescription, to.ShortDescription);
            Assert.AreNotEqual(from.CreatedAt, to.CreatedAt);
        }
Example #2
0
        public void Patch_Should_Ignore_Properties_Not_In_PropertiesToMerge()
        {
            var from = new TestModel
            {
                Id               = 2,
                Name             = "New Test",
                Description      = "Updated description",
                ShortDescription = "Updated short description",
                CreatedAt        = new DateTime(2015, 1, 2)
            };
            var to = new TestModel
            {
                Id               = 1,
                Name             = "Test",
                Description      = "This is a test",
                ShortDescription = "Short description",
                CreatedAt        = new DateTime(2015, 1, 1)
            };
            var propertiesToMerge = new[]
            {
                "id",
                "name"
            };

            var result = new PatchExecutor().Patch(from, to, propertiesToMerge);

            Assert.IsTrue(result);
            Assert.AreEqual(from.Id, to.Id);
            Assert.AreEqual(from.Name, to.Name);
            Assert.AreNotEqual(from.Description, to.Description);
            Assert.AreNotEqual(from.ShortDescription, to.ShortDescription);
            Assert.AreNotEqual(from.CreatedAt, to.CreatedAt);
        }
Example #3
0
        public void Patch_Ignore_Property_Decorated_With_JsonIgnoreAttribute_Return_True()
        {
            var from = new TestModel
            {
                Id          = 1,
                Description = "Original",
            };
            var to = new TestModel
            {
                Id          = 2,
                Description = "New",
            };

            var propertiesToMerge = new[]
            {
                "id",
                "description",
                "modelname"
            };

            var result = new PatchExecutor().Patch(from, to, propertiesToMerge);

            Assert.IsTrue(result);
            Assert.AreEqual(from.Id, to.Id);
            Assert.AreEqual(from.Description, to.Description);
        }
Example #4
0
        public void Patch_Should_Allow_Nullifying_Existing_Properties()
        {
            var from = new TestModel
            {
                Name = string.Empty
            };
            var to = new TestModel
            {
                Name = "Test"
            };
            var propertiesToMerge = new[]
            {
                "name"
            };

            var result = new PatchExecutor().Patch(from, to, propertiesToMerge);

            Assert.IsTrue(result);
            Assert.AreEqual(from.Name, to.Name);
        }
Example #5
0
        public void Patch_Given_Read_Only_Property_Should_Return_False_With_Message()
        {
            var from = new TestModel
            {
                Name = "Original"
            };
            var to = new TestModel()
            {
                Name = "To"
            };
            var propertiesToMerge = new[]
            {
                "name",
                "readonlyname"
            };

            var result = new PatchExecutor().Patch(from, to, propertiesToMerge);

            Assert.IsFalse(result);
            Assert.AreEqual("Could not find writable property: readonlyname", result.Message);
        }
Example #6
0
        public PatchRequestResponse Invoke(PatchRequestArgument arg)
        {
            _log.LogInformation("In PatchRequestComputeFunc.Invoke()");

            try
            {
                // Export requests can be a significant resource commitment. Ensure TPaaS will be listening...
                PerformTPaaSRequestLivelinessCheck(arg);

                // Supply the TRex ID of the Ignite node currently running this code to permit processing contexts to send
                // sub grid results to it.
                arg.TRexNodeID = TRexNodeID.ThisNodeID(StorageMutability.Immutable);

                _log.LogInformation($"Assigned TRexNodeId from local node is {arg.TRexNodeID}");

                var request = new PatchExecutor(arg.ProjectID, arg.Mode, arg.Filters, arg.ReferenceDesign,
                                                arg.TRexNodeID, arg.DataPatchNumber, arg.DataPatchSize, arg.LiftParams);

                _log.LogInformation("Executing request.ExecuteAsync()");

                if (!request.ExecuteAsync().WaitAndUnwrapException())
                {
                    _log.LogError("Request execution failed");
                }

                return(request.PatchSubGridsResponse);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Exception requesting patch");
                return(new PatchRequestResponse {
                    ResultStatus = Types.RequestErrorStatus.Exception
                });
            }
            finally
            {
                _log.LogInformation("Exiting PatchRequestComputeFunc.Invoke()");
            }
        }