public void WhenCorrectInputIsProvidedAndIntersectionIsReturned_ThenIntersectionResponseIsProperlyMappedToApplResponse()
            {
                // Arrange
                var cube = _fixture.Create <Entity.Shape.Cube>();

                var intersectorMock = new Mock <IIntersector <Entity.Shape.Cube, Entity.Shape.Cube> >();

                intersectorMock.Setup(i => i.GetIntersection(It.IsAny <Entity.Shape.Cube>(), It.IsAny <Entity.Shape.Cube>()))
                .Returns(cube);

                var intersectorRegistryMock = new Mock <IIntersectorRegistry>();

                intersectorRegistryMock.Setup(reg => reg.GetIntersector <Entity.Shape.Cube, Entity.Shape.Cube>())
                .Returns(intersectorMock.Object);

                var sut = new IntersectionService(intersectorRegistryMock.Object);

                // Act
                var result = sut.GetIntersection(_fixture.Create <Cube>(), _fixture.Create <Cube>());

                // Assert
                result.Intersection.CenterX.Should().Be(cube.Center.X);
                result.Intersection.CenterY.Should().Be(cube.Center.Y);
                result.Intersection.CenterZ.Should().Be(cube.Center.Z);
                result.Intersection.SizeX.Should().Be(cube.SizeX);
                result.Intersection.SizeY.Should().Be(cube.SizeY);
                result.Intersection.SizeZ.Should().Be(cube.SizeZ);
                result.Intersect.Should().BeTrue();
            }
            public void WhenCorrectInputIsProvided_ThenMethodWorksProperlyWithItsDependencies()
            {
                // Arrange
                var cube = _fixture.Create <Entity.Shape.Cube>();

                var intersectorMock = new Mock <IIntersector <Entity.Shape.Cube, Entity.Shape.Cube> >();

                intersectorMock.Setup(i => i.GetIntersection(It.IsAny <Entity.Shape.Cube>(), It.IsAny <Entity.Shape.Cube>()))
                .Returns(cube);

                var intersectorRegistryMock = new Mock <IIntersectorRegistry>();

                intersectorRegistryMock.Setup(reg => reg.GetIntersector <Entity.Shape.Cube, Entity.Shape.Cube>())
                .Returns(intersectorMock.Object);

                var sut = new IntersectionService(intersectorRegistryMock.Object);

                // Act
                sut.GetIntersection(_fixture.Create <Cube>(), _fixture.Create <Cube>());

                // Assert
                intersectorMock.Verify(i => i.GetIntersection(It.IsAny <Entity.Shape.Cube>(), It.IsAny <Entity.Shape.Cube>()),
                                       Times.Once(), "Method GetIntersection of intersector should be called once.");

                intersectorRegistryMock.Verify(i => i.GetIntersector <Entity.Shape.Cube, Entity.Shape.Cube>(),
                                               Times.Once(), "Method GetIntersector of intersectorRegistry should be called once.");
            }
            public void WhenIntersectionIsReturned_ThenIntersectionResponseValuesAreProperlyRounded()
            {
                // Arrange
                var cube = new Entity.Shape.Cube(
                    new Entity.Shape.Point3D(19.199999999999989, 10.269999999999989, 9.999999999999989),
                    5.400000000000010,
                    2.149999999999989,
                    -2.799999999999989);

                var intersectorMock = new Mock <IIntersector <Entity.Shape.Cube, Entity.Shape.Cube> >();

                intersectorMock.Setup(i => i.GetIntersection(It.IsAny <Entity.Shape.Cube>(), It.IsAny <Entity.Shape.Cube>()))
                .Returns(cube);

                var intersectorRegistryMock = new Mock <IIntersectorRegistry>();

                intersectorRegistryMock.Setup(reg => reg.GetIntersector <Entity.Shape.Cube, Entity.Shape.Cube>())
                .Returns(intersectorMock.Object);

                var sut = new IntersectionService(intersectorRegistryMock.Object);

                // Act
                var result = sut.GetIntersection(_fixture.Create <Cube>(), _fixture.Create <Cube>());

                // Assert
                result.Intersection.CenterX.Should().Be(19.2);
                result.Intersection.CenterY.Should().Be(10.27);
                result.Intersection.CenterZ.Should().Be(10);
                result.Intersection.SizeX.Should().Be(5.4);
                result.Intersection.SizeY.Should().Be(2.15);
                result.Intersection.SizeZ.Should().Be(-2.8);
                result.Intersect.Should().BeTrue();
            }
            public void WhenCubeBIsNull_ThenThrowArgumentNullException()
            {
                // Arrange
                var sut   = new IntersectionService(null);
                var cubeA = _fixture.Create <Cube>();

                // Act
                Action action = () => sut.GetIntersection(cubeA, null);

                // Assert
                action.Should().Throw <ArgumentNullException>();
            }
Ejemplo n.º 5
0
        public void Intersect_With_Another_Cube(float x1, float y1, float side1, float x2, float y2, float side2)
        {
            //Arrange
            var cubeDimensions1     = new CubeDimensions(new X(x1), new Y(y1), new Side(side1));
            var cubeDimensions2     = new CubeDimensions(new X(x2), new Y(y2), new Side(side2));
            var intersectionService = new IntersectionService();

            var cube1 = ShapeFactory.Create(intersectionService, cubeDimensions1);
            var cube2 = ShapeFactory.Create(intersectionService, cubeDimensions2);

            //Act
            var shapeIntersection = cube1.IntersectWith(cube2);

            //Assert
            shapeIntersection.ToString().Should().Be($"Intersection result of a Cube (X = {x1}, Y = {y1}, Side = {side1}) with a Cube (X = {x2}, Y = {y2}, Side = {side2})");
        }
            public void WhenCorrectInputIsProvidedAndNoIntersectionIsReturned_ThenIntersectionResponseIsProperlyMappedToApplResponse()
            {
                // Arrange
                var intersectorMock = new Mock <IIntersector <Entity.Shape.Cube, Entity.Shape.Cube> >();

                intersectorMock.Setup(i => i.GetIntersection(It.IsAny <Entity.Shape.Cube>(), It.IsAny <Entity.Shape.Cube>()))
                .Returns((Entity.Shape.Cube)null);

                var intersectorRegistryMock = new Mock <IIntersectorRegistry>();

                intersectorRegistryMock.Setup(reg => reg.GetIntersector <Entity.Shape.Cube, Entity.Shape.Cube>())
                .Returns(intersectorMock.Object);

                var sut = new IntersectionService(intersectorRegistryMock.Object);

                // Act
                var result = sut.GetIntersection(_fixture.Create <Cube>(), _fixture.Create <Cube>());

                // Assert
                result.Intersect.Should().BeFalse();
            }
 /// <summary>
 /// Creates a new intersection controller.
 /// </summary>
 /// <param name="intersectionService">The intersection service.</param>
 public IntersectionController(IntersectionService intersectionService) => _intersectionService = intersectionService;
Ejemplo n.º 8
0
 public ShapeIntersection IntersectWith(IShape otherShape)
 {
     return(IntersectionService.Intersect(this, otherShape));
 }