Ejemplo n.º 1
0
        public void AddDependency_CanAddANodeDependency()
        {
            // Arrange
            var blendMode = new Mock <IBlendMode>().Object;
            var expected  = new Mock <HeightMapNode>().Object;
            var node      = new BlendingNode(blendMode);

            // Act
            node.AddDependency(expected);

            // Assert
            Assert.Equal(1, node.Dependencies.Count());
            Assert.Equal(expected, node.Dependencies.Single());
        }
Ejemplo n.º 2
0
        private HeightMap GenerateTerrain(int?seed = null)
        {
            var generator1 = new FlatGenerator(1000, 1000, 1);
            var generator2 = new DSNoiseGenerator(1000, 1000, seed: seed);

            var node1 = new GeneratorNode(generator1);
            var node2 = new GeneratorNode(generator2);

            var blend = new BlendingNode(BlendModes.Difference);

            blend.AddDependency(node1);
            blend.AddDependency(node2);
            blend.Execute();

            return(blend.Result);
        }
Ejemplo n.º 3
0
        public void AddDependency_CanAddMultipleNodeDependencies()
        {
            // Arrange
            var blendMode = new Mock <IBlendMode>().Object;
            var expectedA = new Mock <HeightMapNode>().Object;
            var expectedB = new Mock <HeightMapNode>().Object;
            var node      = new BlendingNode(blendMode);

            // Act
            node.AddDependency(expectedA);
            node.AddDependency(expectedB);

            // Assert
            Assert.Equal(2, node.Dependencies.Count());
            Assert.Equal(expectedA, node.Dependencies.First());
            Assert.Equal(expectedB, node.Dependencies.Skip(1).First());
        }
Ejemplo n.º 4
0
        public void ISerializable_SerializeAndDeserializeWithDimensionsCorrectly()
        {
            // Arrange
            var blendMode = new Mock <IBlendMode>().Object;
            var source    = new Mock <HeightMapNode>().Object;
            var expected  = new BlendingNode(20, 10, blendMode);

            expected.AddDependency(source);
            var info = MockSerializationInfo <BlendingNode>();

            // Act
            expected.GetObjectData(info, new StreamingContext());
            var actual = new BlendingNode(info, new StreamingContext());

            // Assert
            Assert.Equal(expected.Dependencies.Count(), actual.Dependencies.Count());
            Assert.Equal(expected.Dependencies.Single(), actual.Dependencies.Single());
            Assert.Equal(expected.BlendMode, actual.BlendMode);
            Assert.Equal(expected.Dimensions, actual.Dimensions);
        }
Ejemplo n.º 5
0
        public void Execute_RunsBlendOnAllPairsOfDependencies()
        {
            // Arrange
            var blendModeMock = new Mock <IBlendMode>();

            blendModeMock.Setup(b => b.Blend(It.IsAny <HeightMap>(), It.IsAny <HeightMap>()))
            .Returns <HeightMap, HeightMap>((h1, h2) => { return(h2); });
            var heightMapA    = new HeightMap(10);
            var heightMapB    = new HeightMap(10);
            var heightMapC    = new HeightMap(10);
            var expectedAMock = new Mock <HeightMapNode>();

            expectedAMock.SetupGet(m => m.Result).Returns(heightMapA);
            var expectedBMock = new Mock <HeightMapNode>();

            expectedBMock.SetupGet(m => m.Result).Returns(heightMapB);
            var expectedCMock = new Mock <HeightMapNode>();

            expectedCMock.SetupGet(m => m.Result).Returns(heightMapC);
            var node = new BlendingNode(blendModeMock.Object);

            node.AddDependency(expectedAMock.Object);
            node.AddDependency(expectedBMock.Object);
            node.AddDependency(expectedCMock.Object);

            // Act
            node.Execute();

            // Assert
            blendModeMock.Verify(m => m.Blend(
                                     It.IsAny <HeightMap>(),
                                     It.Is <HeightMap>(h => h.Equals(heightMapB))), Times.Once);
            blendModeMock.Verify(m => m.Blend(
                                     It.Is <HeightMap>(h => h.Equals(heightMapB)),
                                     It.Is <HeightMap>(h => h.Equals(heightMapC))), Times.Once);
        }