Example #1
0
        public void ChangeOwnerOfPossession_ChangesReflectedInGetPossessionsOfOwner()
        {
            var possession = new TestPossession();

            var ownerOne = new TestOwner();
            var ownerTwo = new TestOwner();

            var relationship = new PossessionRelationship <TestOwner, TestPossession>();

            relationship.ChangeOwnerOfPossession(possession, ownerOne);

            CollectionAssert.Contains(relationship.GetPossessionsOfOwner(ownerOne), possession,
                                      "OwnerOne does not have the possession");

            relationship.ChangeOwnerOfPossession(possession, ownerTwo);

            CollectionAssert.DoesNotContain(relationship.GetPossessionsOfOwner(ownerOne), possession,
                                            "OwnerOne incorrectly has the possession");
            CollectionAssert.Contains(relationship.GetPossessionsOfOwner(ownerTwo), possession,
                                      "OwnerTwo does not have the possession");

            relationship.ChangeOwnerOfPossession(possession, null);
            CollectionAssert.DoesNotContain(relationship.GetPossessionsOfOwner(ownerTwo), possession,
                                            "OwnerTwo falsely has the possession");
        }
 public void Setup()
 {
     _owner       = new TestOwner(_id);
     _contextMock = new Mock <IEntityContext>(MockBehavior.Strict);
     _contextMock.Setup(c => c.BlankIdGenerator).Returns(new DefaultBlankNodeIdGenerator());
     _contextMock.Setup(c => c.Create <TestPair>(It.IsAny <EntityId>())).Returns((EntityId entityId) => CreateKeyValuePair(entityId));
     _contextMock.Setup(c => c.Load <TestOwner>(this._id)).Returns(_owner);
     _context = _contextMock.Object;
 }
Example #3
0
        public void AllMethods_ThrowOnNullPossessionArgument()
        {
            var owner = new TestOwner();

            var relationship = new PossessionRelationship <TestOwner, TestPossession>();

            Assert.Throws <ArgumentNullException>(() => relationship.GetOwnerOfPossession(null),
                                                  "GetOwnerOfPossession did not throw correctly");

            Assert.Throws <ArgumentNullException>(() => relationship.CanChangeOwnerOfPossession(null, owner),
                                                  "CanChangeOwnerOfPossession did not throw correctly");

            Assert.Throws <ArgumentNullException>(() => relationship.ChangeOwnerOfPossession(null, owner),
                                                  "ChangeOwnerOfPossession did not throw correctly");
        }
Example #4
0
        public void CanChangeOwnerOfPossession_FalseIfAlreadyOwnedBy()
        {
            var possession = new TestPossession();

            var owner = new TestOwner();

            var relationship = new PossessionRelationship <TestOwner, TestPossession>();

            Assert.IsFalse(relationship.CanChangeOwnerOfPossession(possession, null),
                           "CanChangeOwnerOfPossession returned an unexpected value");

            relationship.ChangeOwnerOfPossession(possession, owner);

            Assert.IsFalse(relationship.CanChangeOwnerOfPossession(possession, owner),
                           "CanChangeOwnerOfPossession returned an unexpected value");
        }
Example #5
0
        private static TestOwner NewTestObject()
        {
            var source = new TestOwner
            {
                Name  = "source",
                Inner = new CopyTestChild
                {
                    Name = "inner property"
                },
                Inners = new List <CopyTestChild>
                {
                    new CopyTestChild {
                        Name = "inner list item1"
                    },
                    new CopyTestChild {
                        Name = "inner list item2"
                    }
                }
            };

            return(source);
        }
Example #6
0
        //[TestMethod] //this is a performance test
        public void SpeedOfByteArrayConversion()
        {
            var source = new TestOwner
            {
                Inners = new List <CopyTestChild>()
            };
            var count = 5000;

            for (int i = 0; i < count; i++)
            {
                source.Inners.Add(new CopyTestChild
                {
                    Name = i.ToString()
                });
            }

            Stopwatch watch = new Stopwatch();

            watch.Start();
            var byteArray = source.AsByteArray();

            watch.Stop();
            var elapsed = watch.Elapsed;

            Console.WriteLine();
            Console.WriteLine($"copying {count} items into byte array: {elapsed}");
            Console.WriteLine();


            watch  = new Stopwatch();
            source = new TestOwner();
            watch.Start();
            source.ReadFrom(byteArray);
            watch.Stop();
            elapsed = watch.Elapsed;
            Console.WriteLine();
            Console.WriteLine($"copying {count} items out of byte array: {elapsed}");
            Console.WriteLine();
        }
Example #7
0
        public void ChangeOwnerOfPossession_ChangesReflectedInGetOwnerOfPossession()
        {
            var possession = new TestPossession();

            var ownerOne = new TestOwner();
            var ownerTwo = new TestOwner();

            var relationship = new PossessionRelationship <TestOwner, TestPossession>();

            relationship.ChangeOwnerOfPossession(possession, ownerOne);

            Assert.AreEqual(ownerOne, relationship.GetOwnerOfPossession(possession),
                            "GetOwnerOfPossession returned an unexpected value");

            relationship.ChangeOwnerOfPossession(possession, ownerTwo);

            Assert.AreEqual(ownerTwo, relationship.GetOwnerOfPossession(possession),
                            "GetOwnerOfPossession returned an unexpected value");

            relationship.ChangeOwnerOfPossession(possession, null);
            Assert.AreEqual(null, relationship.GetOwnerOfPossession(possession),
                            "GetOwnerOfPossession returned an unexpected value");
        }
Example #8
0
        public void CopyingAnObject()
        {
            var source = NewTestObject();

            var clone1 = new TestOwner {
                Name = "wrong"
            };

            source.CloneTo(clone1);

            var clone2 = new TestOwner {
                Name = "wrong"
            };
            var memento = source.GetMemento();

            memento.Reset();
            memento.WriteTo(clone2);

            var sourceStr  = source.AsString();
            var cloneStr   = clone1.AsString();
            var mementoStr = clone2.AsString();

            Assert.IsTrue(cloneStr == sourceStr && mementoStr == sourceStr);

            //verifying with file: ReaderWriterExtensionTests.CopyingAnObject.approved.txt
            Approvals.Verify($@"
*original:*
{sourceStr}

*after cloning:*
{cloneStr}

*after using memento:*
{mementoStr}
");
        }