예제 #1
0
        public void PatchShouldFailAssertion()
        {
            Patient a = new Patient()
            {
                Key                  = Guid.Empty,
                VersionKey           = Guid.NewGuid(),
                DateOfBirth          = DateTime.MaxValue,
                DateOfBirthPrecision = Model.DataTypes.DatePrecision.Full,
                Identifiers          = new System.Collections.Generic.List <Model.DataTypes.EntityIdentifier>()
                {
                    new Model.DataTypes.EntityIdentifier(Guid.Empty, "1234")
                    {
                        Key = Guid.NewGuid()
                    },
                    new Model.DataTypes.EntityIdentifier(Guid.NewGuid(), "3245")
                    {
                        Key = Guid.NewGuid()
                    }
                },
                Names = new System.Collections.Generic.List <Model.Entities.EntityName>()
                {
                    new Model.Entities.EntityName(NameUseKeys.Legal, "Smith", "Joe")
                    {
                        Key = Guid.NewGuid()
                    }
                },
                Tags = new System.Collections.Generic.List <Model.DataTypes.EntityTag>()
                {
                    new Model.DataTypes.EntityTag("KEY", "VALUE")
                }
            },
                    b = new Patient()
            {
                Key                  = Guid.Empty,
                VersionKey           = Guid.NewGuid(),
                DateOfBirth          = DateTime.MaxValue,
                DateOfBirthPrecision = Model.DataTypes.DatePrecision.Full,
                Identifiers          = new System.Collections.Generic.List <Model.DataTypes.EntityIdentifier>()
                {
                    new Model.DataTypes.EntityIdentifier(Guid.Empty, "1234")
                    {
                        Key = a.Identifiers[0].Key
                    },
                    new Model.DataTypes.EntityIdentifier(Guid.NewGuid(), "3245")
                    {
                        Key = a.Identifiers[1].Key
                    }
                },
                Names = new System.Collections.Generic.List <Model.Entities.EntityName>()
                {
                    new Model.Entities.EntityName(NameUseKeys.Legal, "Smith", "Joseph")
                    {
                        Key = a.Names[0].Key
                    }
                },
                Addresses = new System.Collections.Generic.List <Model.Entities.EntityAddress>()
                {
                    new Model.Entities.EntityAddress(AddressUseKeys.HomeAddress, "123 Main Street West", "Hamilton", "ON", "CA", "L8K5N2")
                },
                Tags = new System.Collections.Generic.List <Model.DataTypes.EntityTag>()
                {
                    new Model.DataTypes.EntityTag("KEY", "VALUE2")
                }
            };

            var patchService = new SimplePatchService();
            var patch        = patchService.Diff(a, b);
            var patchString  = patch.ToString();

            Assert.IsNotNull(patch);
            Assert.AreEqual(15, patch.Operation.Count);

            // Debug info
            this.SerializePatch(patch);

            // 1. Patch should be fine. data now = b
            var data = patchService.Patch(patch, a);

            // 2. Patch should fail, a is different
            a            = a.Clone() as Patient;
            a.VersionKey = Guid.NewGuid();
            try
            {
                data = patchService.Patch(patch, a);
                Assert.Fail();
            }
            catch (PatchAssertionException e)
            {
            }
        }
예제 #2
0
        public void PatchShouldUpdateTargetObject()
        {
            Guid oguid = Guid.NewGuid(),
                 nguid = Guid.NewGuid();

            Patient a = new Patient()
            {
                Key                  = Guid.Empty,
                VersionKey           = Guid.NewGuid(),
                DateOfBirth          = DateTime.MaxValue,
                DateOfBirthPrecision = Model.DataTypes.DatePrecision.Full,
                Identifiers          = new System.Collections.Generic.List <Model.DataTypes.EntityIdentifier>()
                {
                    new Model.DataTypes.EntityIdentifier(Guid.Empty, "1234")
                    {
                        Key = Guid.NewGuid()
                    },
                    new Model.DataTypes.EntityIdentifier(Guid.NewGuid(), "3245")
                    {
                        Key = Guid.NewGuid()
                    }
                },
                Names = new System.Collections.Generic.List <Model.Entities.EntityName>()
                {
                    new Model.Entities.EntityName(NameUseKeys.Legal, "Smith", "Joe")
                    {
                        Key = Guid.NewGuid()
                    },
                    new Model.Entities.EntityName(NameUseKeys.OfficialRecord, "Smith", "Joseph")
                    {
                        Key = Guid.NewGuid()
                    }
                },
                Tags = new System.Collections.Generic.List <Model.DataTypes.EntityTag>()
                {
                    new Model.DataTypes.EntityTag("KEY", "VALUE")
                },
                Relationships = new System.Collections.Generic.List <Model.Entities.EntityRelationship>()
                {
                    new Model.Entities.EntityRelationship()
                    {
                        Key = Guid.NewGuid(),
                        RelationshipTypeKey = EntityRelationshipTypeKeys.DedicatedServiceDeliveryLocation,
                        TargetEntityKey     = oguid
                    }
                }
            },
                    b = new Patient()
            {
                Key                  = Guid.Empty,
                VersionKey           = Guid.NewGuid(),
                DateOfBirth          = DateTime.MaxValue,
                DateOfBirthPrecision = Model.DataTypes.DatePrecision.Day,
                Identifiers          = new System.Collections.Generic.List <Model.DataTypes.EntityIdentifier>()
                {
                    new Model.DataTypes.EntityIdentifier(Guid.Empty, "1234")
                    {
                        Key = a.Identifiers[0].Key
                    }
                },
                Names = new System.Collections.Generic.List <Model.Entities.EntityName>()
                {
                    new Model.Entities.EntityName(NameUseKeys.Legal, "Smith", "Joseph")
                    {
                        Key = a.Names[0].Key
                    }
                },
                Addresses = new System.Collections.Generic.List <Model.Entities.EntityAddress>()
                {
                    new Model.Entities.EntityAddress(AddressUseKeys.HomeAddress, "123 Main Street West", "Hamilton", "ON", "CA", "L8K5N2")
                },
                Tags = new System.Collections.Generic.List <Model.DataTypes.EntityTag>()
                {
                    new Model.DataTypes.EntityTag("KEY", "VALUE2")
                },
                Relationships = new System.Collections.Generic.List <Model.Entities.EntityRelationship>()
                {
                    new Model.Entities.EntityRelationship()
                    {
                        Key = Guid.NewGuid(),
                        RelationshipTypeKey = EntityRelationshipTypeKeys.DedicatedServiceDeliveryLocation,
                        TargetEntityKey     = nguid
                    }
                }
            };

            var patchService = new SimplePatchService();
            var patch        = patchService.Diff(a, b);
            var patchString  = patch.ToString();

            Assert.IsNotNull(patch);
            Assert.AreEqual(15, patch.Operation.Count);

            // Debug info
            patch = this.SerializePatch(patch);

            // 1. Patch should be fine. data now = b
            var data = patchService.Patch(patch, a) as Patient;

            // Should update result
            Assert.AreEqual(1, data.Names.Count);
            Assert.AreEqual(1, data.Identifiers.Count);
            Assert.AreEqual(1, data.Addresses.Count);
            Assert.AreEqual(1, data.Tags.Count);
            Assert.AreEqual("VALUE2", data.Tags[0].Value);
            Assert.AreEqual(b.VersionKey, data.VersionKey);

            // Should not update source
            Assert.AreEqual(2, a.Names.Count);
            Assert.AreEqual(2, a.Identifiers.Count);
            Assert.AreEqual(0, a.Addresses.Count);
            Assert.AreEqual(1, a.Tags.Count);
            Assert.AreEqual("VALUE", a.Tags[0].Value);
            Assert.AreEqual(a.VersionKey, patch.Operation[1].Value);
            Assert.AreEqual(nguid, data.Relationships[0].TargetEntityKey);
        }
예제 #3
0
        public void DiffShouldRemoveNameWithSameValues()
        {
            Patient a = new Patient()
            {
                Key                  = Guid.Empty,
                VersionKey           = Guid.NewGuid(),
                DateOfBirth          = DateTime.MaxValue,
                DateOfBirthPrecision = Model.DataTypes.DatePrecision.Full,
                Identifiers          = new System.Collections.Generic.List <Model.DataTypes.EntityIdentifier>()
                {
                    new Model.DataTypes.EntityIdentifier(Guid.Empty, "1234")
                    {
                        Key = Guid.NewGuid()
                    },
                    new Model.DataTypes.EntityIdentifier(Guid.NewGuid(), "3245")
                    {
                        Key = Guid.NewGuid()
                    }
                },
                Names = new System.Collections.Generic.List <Model.Entities.EntityName>()
                {
                    new Model.Entities.EntityName(NameUseKeys.Legal, "Smith", "Joe")
                    {
                        Key = Guid.NewGuid()
                    }
                },
                Tags = new System.Collections.Generic.List <Model.DataTypes.EntityTag>()
                {
                    new Model.DataTypes.EntityTag("KEY", "VALUE")
                }
            },
                    b = new Patient()
            {
                Key                  = Guid.Empty,
                VersionKey           = Guid.NewGuid(),
                DateOfBirth          = DateTime.MaxValue,
                DateOfBirthPrecision = Model.DataTypes.DatePrecision.Full,
                Identifiers          = new System.Collections.Generic.List <Model.DataTypes.EntityIdentifier>()
                {
                    new Model.DataTypes.EntityIdentifier(Guid.Empty, "1234")
                    {
                        Key = a.Identifiers[0].Key
                    },
                    new Model.DataTypes.EntityIdentifier(Guid.NewGuid(), "3245")
                    {
                        Key = a.Identifiers[1].Key
                    }
                },
                Names = new System.Collections.Generic.List <Model.Entities.EntityName>()
                {
                    new Model.Entities.EntityName(NameUseKeys.Legal, "Smith", "Joseph")
                    {
                        Key = a.Names[0].Key
                    }
                },
                Addresses = new System.Collections.Generic.List <Model.Entities.EntityAddress>()
                {
                    new Model.Entities.EntityAddress(AddressUseKeys.HomeAddress, "123 Main Street West", "Hamilton", "ON", "CA", "L8K5N2")
                },
                Tags = new System.Collections.Generic.List <Model.DataTypes.EntityTag>()
                {
                    new Model.DataTypes.EntityTag("KEY", "VALUE2")
                }
            };

            var patchService = new SimplePatchService();
            var patch        = patchService.Diff(a, b);
            var patchString  = patch.ToString();

            Assert.IsNotNull(patch);
            Assert.AreEqual(11, patch.Operation.Count);

            // Assert there is a remove operation for a name
            Assert.IsTrue(patch.Operation.Any(o => o.OperationType == PatchOperationType.Remove && o.Value.ToString() == a.Names[0].Key.ToString()));
            Assert.IsTrue(patch.Operation.Any(o => o.OperationType == PatchOperationType.Remove && o.Path.Contains("tag.key")));
            this.SerializePatch(patch);

            var result = patchService.Patch(patch, a, true) as Patient;

            Assert.AreEqual(b.Addresses.Count, result.Addresses.Count);
            Assert.AreEqual(b.Names.Count, result.Names.Count);
            Assert.AreEqual(b.Identifiers.Count, result.Identifiers.Count);
            Assert.AreEqual(b.Tags.Count, result.Tags.Count);
            Assert.AreEqual(b.Tags.First().Value, result.Tags.First().Value);
            Assert.AreEqual("Joseph", result.Names.First().Component.Last().Value);
        }