コード例 #1
0
        public void AddChildWithPersistenceInformation()
        {
            DatasetCreationInformation creationInformation = null;

            var storage = new Mock <IPersistenceInformation>();
            var child   = CreateMockDataset();
            var dataset = new Mock <IProxyDataset>();
            {
                dataset.Setup(d => d.StoredAt)
                .Returns(new Mock <IPersistenceInformation>().Object);

                dataset.Setup(d => d.CreateNewChild(It.IsAny <DatasetCreationInformation>()))
                .Callback <DatasetCreationInformation>(d => creationInformation = d)
                .Returns(child);
            }

            var facade      = new DatasetFacade(dataset.Object);
            var childFacade = facade.AddChild(storage.Object);

            Assert.AreEqual(new DatasetFacade(child), childFacade);
            Assert.IsFalse(creationInformation.CanBeAdopted);
            Assert.IsTrue(creationInformation.CanBecomeParent);
            Assert.IsTrue(creationInformation.CanBeCopied);
            Assert.IsTrue(creationInformation.CanBeDeleted);
            Assert.AreEqual(DatasetCreator.User, creationInformation.CreatedOnRequestOf);
            Assert.AreEqual(storage.Object, creationInformation.LoadFrom);
        }
コード例 #2
0
        public void EqualsWithUnequalObjectTypes()
        {
            var first  = new DatasetFacade(CreateMockDataset());
            var second = new object();

            Assert.IsFalse(first.Equals(second));
        }
コード例 #3
0
        public void EqualsWithNullObject()
        {
            var    first  = new DatasetFacade(CreateMockDataset());
            object second = null;

            Assert.IsFalse(first.Equals(second));
        }
コード例 #4
0
        public void AddChildWithNullPersistenceInformation()
        {
            var dataset = new Mock <IProxyDataset>();
            var facade  = new DatasetFacade(dataset.Object);

            Assert.Throws <ArgumentNullException>(() => facade.AddChild(null));
        }
コード例 #5
0
        public void EqualsWithEqualObjects()
        {
            var    dataset = CreateMockDataset();
            var    first   = new DatasetFacade(dataset);
            object second  = new DatasetFacade(dataset);

            Assert.IsTrue(first.Equals(second));
        }
コード例 #6
0
        public void DeleteWithUndeletableDataset()
        {
            var dataset = new Mock <IProxyDataset>();
            {
                dataset.Setup(d => d.CanBeDeleted)
                .Returns(false);
            }

            var facade = new DatasetFacade(dataset.Object);

            Assert.Throws <CannotDeleteDatasetException>(() => facade.Delete());
        }
コード例 #7
0
        public void OnDeactivated()
        {
            var dataset = new Mock <IProxyDataset>();
            var facade  = new DatasetFacade(dataset.Object);

            bool wasUnloaded = false;

            facade.OnDeactivated += (s, e) => wasUnloaded = true;

            dataset.Raise(d => d.OnDeactivated += null, EventArgs.Empty);
            Assert.IsTrue(wasUnloaded);
        }
コード例 #8
0
        public void OnSummaryUpdate()
        {
            var dataset = new Mock <IProxyDataset>();
            var facade  = new DatasetFacade(dataset.Object);

            bool eventRaised = false;

            facade.OnSummaryChanged += (s, e) => { eventRaised = true; };

            dataset.Raise(d => d.OnSummaryChanged += null, new ValueChangedEventArgs <string>("newSummary"));
            Assert.IsTrue(eventRaised);
        }
コード例 #9
0
        public void Summary()
        {
            var dataset = new Mock <IProxyDataset>();
            {
                dataset.SetupProperty(p => p.Summary);
            }

            var facade = new DatasetFacade(dataset.Object);

            var summary = "text";

            facade.Summary = summary;
            Assert.AreEqual(summary, facade.Summary);
        }
コード例 #10
0
        public void Name()
        {
            var dataset = new Mock <IProxyDataset>();
            {
                dataset.SetupProperty(p => p.Name);
            }

            var facade = new DatasetFacade(dataset.Object);

            var name = "name";

            facade.Name = name;
            Assert.AreEqual(name, facade.Name);
        }
コード例 #11
0
        public void ChildrenOf()
        {
            var child   = CreateMockDataset();
            var dataset = new Mock <IProxyDataset>();
            {
                dataset.Setup(d => d.Children())
                .Returns(new List <IProxyDataset> {
                    child
                });
            }

            var facade   = new DatasetFacade(dataset.Object);
            var children = facade.Children();

            Assert.AreEqual(1, children.Count());
            Assert.AreEqual(new DatasetFacade(child), children.First());
        }
コード例 #12
0
        public void Delete()
        {
            var dataset = new Mock <IProxyDataset>();
            {
                dataset.Setup(d => d.CanBeDeleted)
                .Returns(true);

                dataset.Setup(d => d.Delete())
                .Verifiable();
            }

            var facade = new DatasetFacade(dataset.Object);

            facade.Delete();

            dataset.Verify(d => d.Delete(), Times.Once());
        }
コード例 #13
0
        public void Create()
        {
            var dataset = new Mock <IProxyDataset>();
            {
                dataset.Setup(d => d.CanBeAdopted)
                .Returns(true);

                dataset.Setup(d => d.CanBecomeParent)
                .Returns(true);

                dataset.Setup(d => d.CanBeCopied)
                .Returns(true);

                dataset.Setup(d => d.CanBeDeleted)
                .Returns(true);

                dataset.Setup(d => d.IsActivated)
                .Returns(true);

                dataset.Setup(d => d.IsValid)
                .Returns(true);

                dataset.Setup(d => d.CreatedBy)
                .Returns(DatasetCreator.User);
            }

            var facade = new DatasetFacade(dataset.Object);

            Assert.IsTrue(facade.IsValid);
            Assert.AreEqual(dataset.Object.CanBeAdopted, facade.CanBeAdopted);
            Assert.AreEqual(dataset.Object.CanBecomeParent, facade.CanBecomeParent);
            Assert.AreEqual(dataset.Object.CanBeCopied, facade.CanBeCopied);
            Assert.AreEqual(dataset.Object.CanBeDeleted, facade.CanBeDeleted);
            Assert.AreEqual(dataset.Object.IsActivated, facade.IsActivated);
            Assert.AreEqual(dataset.Object.CreatedBy, facade.CreatedBy);
        }