Exemple #1
0
        public void NewGameShouldCreateNewGameFromMoves()
        {
            //arrange
            ServiceProviderMock
            .Setup(a => a.GetService(typeof(IGame)))
            .Returns(GameMock.Object);

            var movesToMake = new[] {
                Move.Center,
                Move.Western,
                Move.Eastern
            };

            GameMock
            .Setup(a => a.IsMoveValid(It.Is <Move>(b => movesToMake.Contains(b))))
            .Returns(true);

            //act
            var newGame = TicTacToeFactory.NewGame(movesToMake);

            //assert
            newGame.Should().BeSameAs(GameMock.Object);

            GameMock
            .Verify(a => a.Move(Move.Center), Times.Once());
            GameMock
            .Verify(a => a.Move(Move.Western), Times.Once());
            GameMock
            .Verify(a => a.Move(Move.Eastern), Times.Once());
        }
        public void ValidateServiceResponseAndPublishException_PublishException()
        {
            var    eventPublished = false;
            string traceId        = "exId",
                   eventKey       = "ek";
            var wc = new WorkContext
            {
                CurrentEntityConfigRecord = new EntityConfigRecord {
                    EventKeys = new EventKeyRecord("create", null, null, null)
                },
                TraceId = traceId
            };
            var eb = new Mock <IEventBus>();

            eb.Setup(e => e.Publish(It.Is <string>(s => s == eventKey), It.Is <DomainEvent>(d => d.Data.GetPropertyValueByName <string>("TraceId") == traceId)))
            .Callback(() => eventPublished = true);

            ServiceProviderMock.Setup(s => s.GetService(typeof(IEventBus))).Returns(eb.Object);
            ServiceProviderMock.Setup(s => s.GetService(typeof(WorkContext))).Returns(wc);

            ServiceResponseWrapperExtensions.Init(ServiceProviderMock.Object);

            var serviceResponse = new ServiceResponse <object>();
            var w  = new ServiceResponseWrapper(serviceResponse);
            var pi = typeof(ServiceResponseWrapper).GetProperty("Exception");

            pi.SetValue(w, new Exception());

            ServiceResponseWrapperExtensions.ValidateServiceResponseAndPublishException <object>(w, eventKey, "ddd");
            eventPublished.ShouldBeTrue();
            serviceResponse.TraceId.ShouldBe(traceId);
        }
Exemple #3
0
        public void NewGameShouldCreateNewGame()
        {
            //arrange
            ServiceProviderMock
            .Setup(a => a.GetService(typeof(IGame)))
            .Returns(GameMock.Object);

            //act
            var newGame = TicTacToeFactory.NewGame();

            //assert
            newGame.Should().BeSameAs(GameMock.Object);
        }
Exemple #4
0
        protected void Init()
        {
            this.PluginExecutionContextMock     = new Mock <IPluginExecutionContext>();
            this.TracingServiceMock             = new Mock <ITracingService>();
            this.OrganizationServiceFactoryMock = new Mock <IOrganizationServiceFactory>();

            InitPluginExecutionContextMock(PluginExecutionContextMock);

            ServiceProviderMock.Setup(provider => provider.GetService(typeof(ITracingService))).Returns(TracingServiceMock.Object);
            ServiceProviderMock.Setup(provider => provider.GetService(typeof(IOrganizationServiceFactory))).Returns(OrganizationServiceFactoryMock.Object);
            ServiceProviderMock.Setup(provider => provider.GetService(typeof(IPluginExecutionContext))).Returns(PluginExecutionContextMock.Object);

            OrganizationServiceFactoryMock.Setup(factory => factory.CreateOrganizationService(It.IsAny <Guid?>())).Returns(OrganizationService);
        }
Exemple #5
0
        public void SmokeTest()
        {
            ServiceProviderMock
            .Setup(sp => sp.GetService(typeof(TestValidator1)))
            .Returns(() => new TestValidator1());

            var provider = new ValidatorProvider(ServiceProviderMock.Object, LoggerMock.Object);
            var result   = provider.GetValidator(nameof(TestValidator1));

            ServiceProviderMock
            .Verify(sp => sp.GetService(typeof(TestValidator1)), Times.Once());

            Assert.IsType <TestValidator1>(result);
        }
Exemple #6
0
            public void CanGetValidator()
            {
                var validator     = new TestValidator();
                var validatorType = validator.GetType();

                ServiceProviderMock
                .Setup(sp => sp.GetService(validatorType))
                .Returns(() => validator);

                var result = Target.GetValidator(ValidatorUtility.GetValidatorName(validatorType));

                ServiceProviderMock
                .Verify(sp => sp.GetService(validatorType), Times.Once);
                Assert.IsType(validatorType, result);
            }
Exemple #7
0
        public void NewGameShouldThrowWhenMoveIsInvalid()
        {
            //arrange
            ServiceProviderMock
            .Setup(a => a.GetService(typeof(IGame)))
            .Returns(GameMock.Object);

            var movesToMake = new[] {
                Move.Center
            };

            GameMock
            .Setup(a => a.IsMoveValid(Move.Center))
            .Returns(false);

            //act
            Action act = () => TicTacToeFactory.NewGame(movesToMake);

            //assert
            act
            .ShouldThrow <GameException>()
            .WithMessage("Invalid move passed in. Cannot create game from moves.");
        }
Exemple #8
0
 private void Config(bool isValidChassi)
 {
     ChassiValidationServiceMock = new Mock <IChassiUniqueValidationService>();
     ServiceProviderMock.Setup(p => p.GetService(typeof(IChassiUniqueValidationService))).Returns(ChassiValidationServiceMock.Object);
     ChassiValidationServiceMock.Setup(r => r.IsValid(It.IsAny <string>())).Returns(isValidChassi);
 }