public void Accept_Changes_Should_Remove_ModifiedProperties_From_Family()
        {
            // Arrange
            var parent = new MockFamily().Parent;

            parent.ModifiedProperties = new List <string> {
                "Name"
            };
            parent.Children[0].ModifiedProperties = new List <string> {
                "Name"
            };
            parent.Children[0].Children[0].ModifiedProperties = new List <string> {
                "Name"
            };
            parent.Children[0].Children[0].Children[1].ModifiedProperties = new List <string> {
                "Name"
            };

            // Act
            var context = _fixture.GetContext();

            context.AcceptChanges(parent);

            // Assert
            IEnumerable <ICollection <string> > modifiedProps = context.GetModifiedProperties(parent);

            Assert.DoesNotContain(modifiedProps, p => p?.Count > 0);
        }
        public void Apply_Changes_Should_Mark_Grandchild_Deleted()
        {
            // Arrange
            var context = _fixture.GetContext();
            var parent  = new MockFamily().Parent;

            parent.Children.RemoveAt(2);
            parent.Children.RemoveAt(1);
            var child = parent.Children[0];

            child.Children.RemoveAt(2);
            child.Children.RemoveAt(1);
            var grandchild = child.Children[0];

            grandchild.Children      = null;
            parent.TrackingState     = TrackingState.Unchanged;
            child.TrackingState      = TrackingState.Deleted;
            grandchild.TrackingState = TrackingState.Deleted;

            // Act
            context.ApplyChanges(parent);

            // Assert
            Assert.Equal(EntityState.Unchanged, context.Entry(parent).State);
            Assert.Equal(EntityState.Deleted, context.Entry(child).State);
            Assert.Equal(EntityState.Deleted, context.Entry(grandchild).State);
        }
        public void Accept_Changes_Should_Mark_Family_Unchanged()
        {
            // Arrange
            var parent = new MockFamily().Parent;

            parent.TrackingState                                     = TrackingState.Modified;
            parent.Children[0].TrackingState                         = TrackingState.Modified;
            parent.Children[0].Children[0].TrackingState             = TrackingState.Modified;
            parent.Children[0].Children[0].Children[0].TrackingState = TrackingState.Added;
            parent.Children[0].Children[0].Children[1].TrackingState = TrackingState.Modified;
            parent.Children[0].Children[0].Children[2].TrackingState = TrackingState.Deleted;
            parent.Children[1].TrackingState                         = TrackingState.Added;
            parent.Children[1].Children[0].TrackingState             = TrackingState.Added;
            parent.Children[1].Children[0].Children[0].TrackingState = TrackingState.Added;
            parent.Children[1].Children[0].Children[1].TrackingState = TrackingState.Added;
            parent.Children[1].Children[0].Children[2].TrackingState = TrackingState.Added;
            parent.Children[2].TrackingState                         = TrackingState.Deleted;
            parent.Children[2].Children[1].TrackingState             = TrackingState.Deleted;
            parent.Children[2].Children[1].Children[0].TrackingState = TrackingState.Deleted;
            parent.Children[2].Children[1].Children[1].TrackingState = TrackingState.Deleted;
            parent.Children[2].Children[1].Children[2].TrackingState = TrackingState.Deleted;

            // Act
            var context = _fixture.GetContext();

            context.AcceptChanges(parent);

            // Assert
            var states = context.GetTrackingStates(parent, TrackingState.Unchanged).ToList();

            Assert.Equal(40, states.Count);
        }
示例#4
0
        public void Accept_Changes_Should_Remove_Family_Deleted()
        {
            // Arrange
            var parent = new MockFamily().Parent;

            parent.TrackingState                                     = TrackingState.Modified;
            parent.Children[0].TrackingState                         = TrackingState.Modified;
            parent.Children[0].Children[0].TrackingState             = TrackingState.Modified;
            parent.Children[0].Children[0].Children[0].TrackingState = TrackingState.Added;
            parent.Children[0].Children[0].Children[1].TrackingState = TrackingState.Modified;
            parent.Children[0].Children[0].Children[2].TrackingState = TrackingState.Deleted;
            parent.Children[1].TrackingState                         = TrackingState.Added;
            parent.Children[1].Children[0].TrackingState             = TrackingState.Added;
            parent.Children[1].Children[0].Children[0].TrackingState = TrackingState.Added;
            parent.Children[1].Children[0].Children[1].TrackingState = TrackingState.Added;
            parent.Children[1].Children[0].Children[2].TrackingState = TrackingState.Added;
            parent.Children[2].TrackingState                         = TrackingState.Deleted;
            parent.Children[2].Children[1].TrackingState             = TrackingState.Deleted;
            parent.Children[2].Children[1].Children[0].TrackingState = TrackingState.Deleted;
            parent.Children[2].Children[1].Children[1].TrackingState = TrackingState.Deleted;
            parent.Children[2].Children[1].Children[2].TrackingState = TrackingState.Deleted;

            // Act
            parent.AcceptChanges();

            // Assert
            Assert.Equal(2, parent.Children.Count);
            Assert.Equal(2, parent.Children[0].Children[0].Children.Count);
        }
示例#5
0
        public void Accept_Changes_Should_Remove_ModifiedProperties_From_Family()
        {
            // Arrange
            var parent = new MockFamily().Parent;

            parent.ModifiedProperties = new List <string> {
                "Name"
            };
            parent.Children[0].ModifiedProperties = new List <string> {
                "Name"
            };
            parent.Children[0].Children[0].ModifiedProperties = new List <string> {
                "Name"
            };
            parent.Children[0].Children[0].Children[1].ModifiedProperties = new List <string> {
                "Name"
            };

            // Act
            parent.AcceptChanges();

            // Assert
            IEnumerable <IEnumerable <string> > modifiedProps = parent.GetModifiedProperties();

            Assert.False(modifiedProps.Any(p => p != null));
        }
示例#6
0
        public void Accept_Changes_Should_Mark_Family_Unchanged()
        {
            // Arrange
            var parent = new MockFamily().Parent;

            parent.TrackingState                                     = TrackingState.Modified;
            parent.Children[0].TrackingState                         = TrackingState.Modified;
            parent.Children[0].Children[0].TrackingState             = TrackingState.Modified;
            parent.Children[0].Children[0].Children[0].TrackingState = TrackingState.Added;
            parent.Children[0].Children[0].Children[1].TrackingState = TrackingState.Modified;
            parent.Children[0].Children[0].Children[2].TrackingState = TrackingState.Deleted;
            parent.Children[1].TrackingState                         = TrackingState.Added;
            parent.Children[1].Children[0].TrackingState             = TrackingState.Added;
            parent.Children[1].Children[0].Children[0].TrackingState = TrackingState.Added;
            parent.Children[1].Children[0].Children[1].TrackingState = TrackingState.Added;
            parent.Children[1].Children[0].Children[2].TrackingState = TrackingState.Added;
            parent.Children[2].TrackingState                         = TrackingState.Deleted;
            parent.Children[2].Children[1].TrackingState             = TrackingState.Deleted;
            parent.Children[2].Children[1].Children[0].TrackingState = TrackingState.Deleted;
            parent.Children[2].Children[1].Children[1].TrackingState = TrackingState.Deleted;
            parent.Children[2].Children[1].Children[2].TrackingState = TrackingState.Deleted;

            // Act
            parent.AcceptChanges();

            // Assert
            var states = parent.GetTrackingStates(TrackingState.Unchanged).ToList();

            Assert.Equal(27, states.Count());
        }
        public void Apply_Changes_Should_Mark_Family_Unchanged()
        {
            // Arrange
            var context = TestsHelper.CreateFamilyDbContext(CreateFamilyDbOptions);
            var parent  = new MockFamily().Parent;

            // Act
            context.ApplyChanges(parent);

            // Assert
            IEnumerable <EntityState> states = context.GetEntityStates(parent, EntityState.Unchanged);

            Assert.AreEqual(40, states.Count());
        }
        public void Apply_Changes_Should_Mark_Family_Unchanged()
        {
            // Arrange
            var context = _fixture.GetContext();
            var parent  = new MockFamily().Parent;

            // Act
            context.ApplyChanges(parent);

            // Assert
            var expectedState = EntityState.Unchanged;
            var states        = context.GetEntityStates(parent, expectedState).ToList();

            TestHelpers.AssertStates(states, expectedState);
        }
示例#9
0
        public void Apply_Changes_Should_Mark_ComplexType_Modified()
        {
            // Arrange
            var context = TestsHelper.CreateFamilyDbContext(CreateFamilyDbOptions);
            var parent  = new MockFamily().Parent;

            parent.Address.StreetName         = "123 Lee Ave.";
            parent.Address.ModifiedProperties = new[] { nameof(Address.StreetName) };
            parent.Address.TrackingState      = TrackingState.Modified;

            // Act
            context.ApplyChanges(parent);

            // Assert
            Assert.True(context.Entry(parent).ComplexProperty(p => p.Address).IsModified);
        }
示例#10
0
        public TestDataspace(string name, DateTime creation)
            : base(name)
        {
            Logger = LogManager.GetLogger(GetType());

            RootProperty = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("a48c9c25-1e3a-43c8-be6a-044224cc69cb"),
                Title         = "property",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "unitless",
            };

            Velocity = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("d80b7b4d-f51d-4821-b1db-c595f18c51db"),
                Title         = "velocity",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "length per time",
            };

            PenetrationRate = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("d2b70df2-6df3-4751-bd02-150e3fc96450"),
                Title         = "penetration rate",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "length per time",
            };

            AvgPenetrationRate = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("7fbf2718-f45a-444e-ae3c-17f79f8817e2"),
                Title         = "avg penetration rate",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "length per time",
            };

            Force = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("a5789b56-72a3-4561-b906-b5ba13852c23"),
                Title         = "force",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "force",
            };

            Load = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("3bf92c0b-b712-4128-b7bc-b21e0270d9be"),
                Title         = "load",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "force",
            };

            HookLoad = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("d0a7c1c5-73da-45b5-a762-eb49721d91e9"),
                Title         = "hook load",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "force",
            };

            Length = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("4a305182-221e-4205-9e7c-a36b06fa5b3d"),
                Title         = "length",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "length",
            };

            Depth = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("4364b378-899a-403a-8401-b06abd4fc0cf"),
                Title         = "depth",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "length",
            };

            MeasuredDepth = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("c48c65d4-9680-4d10-903c-a1b2e30f66b5"),
                Title         = "measured depth",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "length",
            };

            Time = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("3a72f130-4ebf-4ea9-a330-a610a4e4ed0e"),
                Title         = "time",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "time",
            };

            AbsoluteTime = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("df21fba2-fe8c-4d66-9a73-fbd0e6013abb"),
                Title         = "absolute time",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "time",
            };

            TimeStamp = new MockPropertyKind
            {
                Dataspace     = this,
                Uuid          = Guid.Parse("6a2ecc9b-7561-41eb-8c6d-adf83538c085"),
                Title         = "time stamp",
                Creation      = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                LastUpdate    = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(),
                IsAbstract    = "false",
                QuantityClass = "time",
            };

            Velocity.SetParent(RootProperty, creation);
            PenetrationRate.SetParent(Velocity, creation);
            AvgPenetrationRate.SetParent(PenetrationRate, creation);

            Force.SetParent(RootProperty, creation);
            Load.SetParent(Force, creation);
            HookLoad.SetParent(Load, creation);

            Length.SetParent(RootProperty, creation);
            Depth.SetParent(Length, creation);
            MeasuredDepth.SetParent(Depth, creation);

            Time.SetParent(RootProperty, creation);
            AbsoluteTime.SetParent(Time, creation);
            TimeStamp.SetParent(AbsoluteTime, creation);

            Well01 = new MockWell
            {
                Dataspace  = this,
                Title      = "Well 01",
                Creation   = creation,
                LastUpdate = creation,
            };

            Well02 = new MockWell
            {
                Dataspace  = this,
                Title      = "Well 02",
                Creation   = creation,
                LastUpdate = creation,
            };
            Wellbore01 = new MockWellbore
            {
                Dataspace  = this,
                Title      = "Wellbore 01",
                Creation   = creation,
                LastUpdate = creation,
            };
            Wellbore01.SetWell(Well01, creation);

            Wellbore02 = new MockWellbore
            {
                Dataspace  = this,
                Title      = "Wellbore 02",
                Creation   = creation,
                LastUpdate = creation,
            };
            Wellbore02.SetWell(Well01, creation);

            Wellbore03 = new MockWellbore
            {
                Dataspace  = this,
                Title      = "Wellbore 03 - Deleted Periodically",
                Creation   = creation,
                LastUpdate = creation,
            };
            Wellbore03.SetWell(Well01, creation);

            Wellbore04 = new MockWellbore
            {
                Dataspace  = this,
                Title      = "Wellbore 04 - Permanently Deleted",
                Creation   = creation,
                LastUpdate = creation,
            };
            Wellbore04.SetWell(Well01, creation);

            Wellbore05 = new MockWellbore
            {
                Dataspace  = this,
                Title      = "Wellbore 05 - Automatic Subscription",
                Creation   = creation,
                LastUpdate = creation,
            };
            Wellbore05.SetWell(Well01, creation);

            TimeChannel01 = new MockChannel(true)
            {
                Dataspace  = this,
                Title      = "Average ROP",
                Creation   = creation,
                LastUpdate = creation,

                ChannelPropertyKind = AvgPenetrationRate,
                Mnemonic            = "ROPA",
                Uom = "m/h",
            };
            TimeChannel01.SetWellbore(Wellbore01, creation);

            TimeChannel02 = new MockChannel(true)
            {
                Dataspace  = this,
                Title      = "Hook Load",
                Creation   = creation,
                LastUpdate = creation,

                ChannelPropertyKind = HookLoad,
                Mnemonic            = "HKLD",
                Uom = "10 kN",
            };
            TimeChannel02.SetWellbore(Wellbore01, creation);

            TimeChannel03 = new MockChannel(true)
            {
                Dataspace  = this,
                Title      = "Bit Depth - Periodically Deleted",
                Creation   = creation,
                LastUpdate = creation,

                ChannelPropertyKind = MeasuredDepth,
                Mnemonic            = "BDEP",
                Uom = "m",
            };
            TimeChannel03.SetWellbore(Wellbore01, creation);

            TimeChannel04 = new MockChannel(true)
            {
                Dataspace  = this,
                Title      = "Hole Depth - Periodically Unjoined",
                Creation   = creation,
                LastUpdate = creation,

                ChannelPropertyKind = MeasuredDepth,
                Mnemonic            = "HDEP",
                Uom = "m",
            };
            TimeChannel04.SetWellbore(Wellbore01, creation);

            TimeChannelSet01 = new MockChannelSet
            {
                Dataspace  = this,
                Title      = "Time ChannelSet 01",
                Creation   = creation,
                LastUpdate = creation,
            };
            TimeChannelSet01.SetWellbore(Wellbore01, creation);
            TimeChannel01.JoinContainer(TimeChannelSet01, creation);
            TimeChannel02.JoinContainer(TimeChannelSet01, creation);
            TimeChannel03.JoinContainer(TimeChannelSet01, creation);
            TimeChannel04.JoinContainer(TimeChannelSet01, creation);

            DepthChannel01 = new MockChannel(false)
            {
                Dataspace  = this,
                Title      = "Average ROP",
                Creation   = creation,
                LastUpdate = creation,

                ChannelPropertyKind = AvgPenetrationRate,
                Mnemonic            = "ROPA",
                Uom = "m/h",
            };
            DepthChannel01.SetWellbore(Wellbore01, creation);

            DepthChannel02 = new MockChannel(false)
            {
                Dataspace  = this,
                Title      = "Hook Load",
                Creation   = creation,
                LastUpdate = creation,

                ChannelPropertyKind = HookLoad,
                Mnemonic            = "HKLD",
                Uom = "10 kN",
            };
            DepthChannel02.SetWellbore(Wellbore01, creation);

            DepthChannelSet01 = new MockChannelSet
            {
                Dataspace  = this,
                Title      = "Depth ChannelSet 01",
                Creation   = creation,
                LastUpdate = creation,
            };
            DepthChannelSet01.SetWellbore(Wellbore01, creation);
            DepthChannel01.JoinContainer(DepthChannelSet01, creation);
            DepthChannel02.JoinContainer(DepthChannelSet01, creation);

            var objects = new List <MockObject>
            {
                Well01,
                Well02,
                Wellbore01,
                Wellbore02,
                Wellbore03,
                Wellbore05,
                RootProperty,
                Velocity,
                PenetrationRate,
                AvgPenetrationRate,
                Force,
                Load,
                HookLoad,
                Length,
                Depth,
                MeasuredDepth,
                Time,
                AbsoluteTime,
                TimeStamp,
                TimeChannelSet01,
                TimeChannel01,
                TimeChannel02,
                TimeChannel03,
                TimeChannel04,
                DepthChannelSet01,
                DepthChannel01,
                DepthChannel02,
            };

            Objects.Clear();
            foreach (var @object in objects)
            {
                Objects[@object.Uuid] = @object;
                @object.Create(creation);
            }

            var deletedObjects = new List <MockObject>
            {
                Wellbore04,
            };

            DeletedObjects.Clear();
            foreach (var deletedObject in deletedObjects)
            {
                DeletedObjects[deletedObject.Uuid] = deletedObject;
            }

            Witsml = new MockFamily
            {
                Dataspace = this,
                Title     = "WITSML Store (2.0)",
                Type      = MockWitsmlObject.Type,
            };

            Eml = new MockFamily
            {
                Dataspace = this,
                Title     = "EML Common (2.1)",
                Type      = MockCommonObject.Type,
            };

            var families = new List <MockFamily> {
                Witsml, Eml
            };

            Families.Clear();
            Families.AddRange(families);
        }
 public void Init()
 {
     // Create new mock database for each test
     _family = new MockFamily();
 }
示例#12
0
 public TrackableExtensionsTests()
 {
     // Create new mock database for each test
     _family = new MockFamily();
 }