예제 #1
0
        public void GetFigure_ShouldThrowInvalidOperationException_IfFigureTypeKeyDoesNotExist()
        {
            var factoryMock = new Mock <FigureFactory>();
            var factories   = new Dictionary <FigureType, FigureFactory>()
            {
                [FigureType.Circle] = factoryMock.Object
            };
            var resolver   = new FigureResolver(factories);
            var parameters = new double[] { 1, 2, 3 };

            Assert.Throws <InvalidOperationException>(() =>
            {
                resolver.GetFigure(FigureType.Triangle, parameters);
            });
        }
예제 #2
0
        public void GetFigure_ShouldReturnFigure_IfFigureTypeKeyExists()
        {
            // Arrange
            var factoryMock = new Mock <FigureFactory>();
            var figureMock  = new Mock <IFigure>();
            var factories   = new Dictionary <FigureType, FigureFactory>()
            {
                [FigureType.Circle] = factoryMock.Object
            };
            var resolver   = new FigureResolver(factories);
            var parameters = new double[] { 1, 2, 3 };

            factoryMock.Setup(f => f.CreateFigure(parameters)).Returns(figureMock.Object);

            // Act
            var figure = resolver.GetFigure(FigureType.Circle, parameters);

            // Assert
            factoryMock.Verify(f => f.CreateFigure(parameters), Times.Once);
            Assert.Equal(figureMock.Object, figure);
        }