Esempio n. 1
0
        public void should_not_be_able_to_get_pawn_by_id_if_its_not_registered()
        {
            // Setup
            var basicPawn = new BasicPawn {
                Name = "Name"
            };

            var basicPawnContainer = new BlGraphContainer
            {
                BlContainerName = "BasicPawn", StorageContainerName = "BasicPawn"
            };
            var containerList = new List <BlGraphContainer> {
                basicPawnContainer
            };
            var graphMock = new Mock <IBlGraph>();

            graphMock.Setup(graph => graph.CompiledCollections).Returns(containerList);

            var storageProviderMock = new Mock <IBlStorageProvider>();

            storageProviderMock
            .Setup(provider => provider.GetById <BasicPawn>(It.IsAny <string>(), null))
            .Returns(basicPawn);

            var bls = new Bls(storageProviderMock.Object, graphMock.Object);

            // Act & Assert
            Assert.Throws <PawnNotRegisteredError>(() =>
            {
                bls.GetById <BasicPawn>("123");
            });
        }
Esempio n. 2
0
        public void should_spawn_new_pawn()
        {
            // Setup
            var graphContainer = new BlGraphContainer
            {
                BlContainerName      = "BasicPawn",
                StorageContainerName = "BasicPawn"
            };
            var containerList = new List <BlGraphContainer> {
                graphContainer
            };

            var graphMock = new Mock <IBlGraph>();

            graphMock.Setup(graph => graph.CompiledCollections).Returns(containerList);

            // Act
            Bls bls = new Bls(null, graphMock.Object);

            bls.RegisterBlPawns(new BasicPawn());

            BasicPawn basicPawn = bls.SpawnNew <BasicPawn>();

            // Assert
            Assert.NotNull(basicPawn);
            Assert.Single(bls.ToAddBuffer);
        }
Esempio n. 3
0
        public void ShouldTrackChanges()
        {
            // Setup
            var pn        = new BasicPawn();
            var basicPawn = pn.AsTrackable();

            // Act
            basicPawn.Name = "Some Name";
            var traceable = basicPawn.CastToIChangeTrackable();

            // Assert
            Assert.True(traceable.IsChanged);
            Assert.Equal(ChangeStatus.Changed, traceable.ChangeTrackingStatus);
        }
Esempio n. 4
0
        public void should_add_to_set_one_distinct_pawns_from_two_instances_no_ids()
        {
            // Setup
            var       set = new HashSet <BlsPawn>();
            BasicPawn p1  = new BasicPawn {
                Name = "p1"
            };

            // Act
            set.Add(p1);
            set.Add(p1);

            // Assert
            Assert.Single(set);
        }
Esempio n. 5
0
        public void should_add_to_set_two_distinct_pawns_with_no_ids()
        {
            // Setup
            var       set = new HashSet <BlsPawn>();
            BasicPawn p1  = new BasicPawn {
                Name = "p1"
            };
            BasicPawn p2 = new BasicPawn {
                Name = "p2"
            };

            // Act
            set.Add(p1);
            set.Add(p2);

            // Assert
            Assert.Equal(2, set.Count);
        }
Esempio n. 6
0
        public void should_add_to_set_one_distinct_pawns_from_two_same_ids()
        {
            // Setup
            var       set = new HashSet <BlsPawn>();
            BasicPawn p1  = new BasicPawn {
                Name = "p1"
            };

            p1.SetId("id_of_p");
            BasicPawn p2 = new BasicPawn {
                Name = "p2"
            };

            p2.SetId("id_of_p");

            // Act
            set.Add(p1);
            set.Add(p2);

            // Assert
            Assert.Single(set);
        }
Esempio n. 7
0
        public void should_be_able_to_get_pawn_by_id()
        {
            // Setup
            var basicPawn = new BasicPawn {
                Name = "Name"
            };

            basicPawn.SetId("123_id");

            var basicPawnContainer = new BlGraphContainer
            {
                BlContainerName      = "BasicPawn",
                StorageContainerName = "BasicPawn",
                Properties           = new List <BlContainerProp>()
            };
            var containerList = new List <BlGraphContainer> {
                basicPawnContainer
            };
            var graphMock = new Mock <IBlGraph>();

            graphMock.Setup(graph => graph.GetStorageContainerNameForPawn(It.IsAny <BasicPawn>())).Returns("BasicPawn");
            graphMock.Setup(graph => graph.CompiledCollections).Returns(containerList);

            var storageProviderMock = new Mock <IBlStorageProvider>();

            storageProviderMock.Setup(provider
                                      => provider.GetById <BasicPawn>(It.IsAny <string>(), It.IsAny <string>())).Returns(basicPawn);
            var bls = new Bls(storageProviderMock.Object, graphMock.Object);

            bls.RegisterBlPawns(new BasicPawn());

            // Act
            var found = bls.GetById <BasicPawn>("123");

            // Assert
            Assert.NotNull(found);
            storageProviderMock.Verify(provider => provider.GetById <BasicPawn>("123", "BasicPawn"), Times.Once());
        }