protected AppendEntryBaseTest()
        {
            // Arrange  
            var mocker = new AutoMocker();

            ServerIdentifier = new ServerIdentifier();

            mocker.Use(ServerIdentifier);

            mocker.Setup<ISubject<AppendEntryMessage>>(p => p.Subscribe(It.IsAny<IObserver<AppendEntryMessage>>()))
                .Callback<IObserver<AppendEntryMessage>>((o) =>
                {
                    AppendEntryCallback = o;
                });
            AppendEntryCallback = mocker.Get<ISubject<AppendEntryMessage>>();

            AppendEntryResult = new Subject<AppendEntryResultMessage>();
            Election = new Election();
            LogReplication = new LogReplication();
            
            AppendEntry = new Rafting.AppendEntry(AppendEntryResult,
                mocker.Get<ISubject<AppendEntryMessage>>(),
                mocker.Get<IHartbeatTimer>(),
                LogReplication,
                Election,
                mocker.Get<ILoggerFactory>(),
                new RaftOptions(),
                mocker.Get<ServerIdentifier>(),
                null);
        }
        public void DisposeAndStateDoesNotChangeAfterHartbeatTest()
        {
            var mocker = new AutoMocker();
            var serverIdentifier = new ServerIdentifier();

            mocker.Use(serverIdentifier);

            var options = new RaftOptions();
            options.Hartbeat.FromMilliseconds = 50;
            options.Hartbeat.ToMilliseconds = 50;

            var timer = new HartbeatTimer(options, mocker.Get<ILoggerFactory>(), serverIdentifier);
            var state = ServerStateType.Leader;

            var dispose = timer.Subscribe((s) =>
            {
                state = s;
            });

            dispose.Dispose();

            Thread.Sleep(100);

            Assert.Equal(ServerStateType.Leader, state);
        }
        public CandidateBaseTests()
        {
            var mocker = new AutoMocker();

            ServerIdentifier = new ServerIdentifier();
            mocker.Use(ServerIdentifier);


            Election = new Election();
            RequestVoteResult = new Subject<RequestVoteResultMessage>();
            RequestVote = new Subject<RequestVoteMessage>();
            MockVotingSystem = mocker.GetMock<IVotingSystem>();


            Candidate = new Rafting.States.Candidate(mocker.Get<ServerIdentifier>(),
                mocker.Get<IElectionTimer>(),
                RequestVote,
                RequestVoteResult,
                MockVotingSystem.Object,
                Election,
                mocker.Get<ILogReplication>(),
                mocker.Get<Nodes>(),
                mocker.Get<ILoggerFactory>(),
                new RaftOptions());
        }
        protected VoteReceivedBaseTests()
        {
            // Arrange
            var mocker = new AutoMocker();

            ServerIdentifier = new ServerIdentifier();

            mocker.Use(ServerIdentifier);

            mocker.Setup<ISubject<RequestVoteMessage>>(p => p.Subscribe(It.IsAny<IObserver<RequestVoteMessage>>()))
                .Callback<IObserver<RequestVoteMessage>>((o) =>
                {
                    RequestVoteCallback = o;
                });
            RequestVoteCallback = mocker.Get<ISubject<RequestVoteMessage>>();

            Election = new Election();

            Message = new RequestVoteResultMessage();

            mocker.Setup<ISubject<RequestVoteResultMessage>>(p => p.OnNext(It.IsAny<RequestVoteResultMessage>()))
                .Callback<RequestVoteResultMessage>((o) =>
                {
                    Message = o;
                });

            VoteReceived = new Rafting.VoteReceived(mocker.Get<ISubject<RequestVoteResultMessage>>(),
                mocker.Get<ServerIdentifier>(),
                mocker.Get<ISubject<RequestVoteMessage>>(),
                Election,
                mocker.Get<ILoggerFactory>(),
                new Nodes(),
                new RaftOptions(),
                mocker.Get<ILogReplication>());
        }
Beispiel #5
0
        public void TestMoqVersionRedirect()
        {
            var mocker = new AutoMocker();
            mocker.Setup<IMockableThing>(mock => mock.SayHello(It.IsAny<string>())).Returns("Hello Peter");

            var sut = mocker.CreateInstance<Fake>();

            Assert.That(sut.SayHello("Peter"), Is.EqualTo("Hello Peter"));
        }
        public void SetUp()
        {
            var mocker = new AutoMocker();
            dataManipulator = mocker.GetMock<IHmrcDataManipulator>();
            configRepository = mocker.GetMock<IConfigurationRepository>();
            messageSender = mocker.GetMock<IMessageSender>();

            messageSender.Setup(x => x.PostXml(It.IsAny<string>(), It.IsAny<string>())).Returns(GetPostResult());

            proxyService = mocker.CreateInstance<ProxyService>();
        }
Beispiel #7
0
        public void Init()
        {
            var mocker = new AutoMocker();

            var machine = new Machine<State, Trigger>(State.First,
                mocker.Get<ILoggerFactory>(),
                mocker.Get<IObservableProvider>());

            machine.On(State.First).
                OnEntry(() =>
                {
                    Assert.Equal(State.First, machine.State);

                    System.Console.WriteLine($"first {machine.State}");
                })
                .Permit(Trigger.ChangeToSecond, State.Second)
                .Permit(Trigger.ChangeToFirst, State.First);

            machine.On(State.Second).
                OnEntry(() =>
                {
                    Assert.Equal(State.Second, machine.State);

                    System.Console.WriteLine($"second {machine.State}");
                })
                .Permit(Trigger.ChangeToSecond, State.Second)
                .Permit(Trigger.ChangeToThird, State.Third);

            machine.On(State.Third).
                OnEntry(() =>
                {
                    Assert.Equal(State.Third, machine.State);
                });

            machine.OnNext(Trigger.ChangeToFirst);

            Assert.Equal(State.First, machine.State);

            machine.OnNext(Trigger.ChangeToThird);

            Assert.Equal(State.First, machine.State);

            machine.OnNext(Trigger.ChangeToSecond);

            Assert.Equal(State.Second, machine.State);

            machine.OnNext(Trigger.ChangeToThird);

            Assert.Equal(State.Third, machine.State);

            machine.OnNext(Trigger.ChangeToFirst);


        }
Beispiel #8
0
        public void ChangeStates()
        {
            // Arrange
            var mocker = new AutoMocker();
            mocker.Setup<IHartbeatTimer>(p => p.Reset()).Callback(() =>
            {

            });

            var mockFollower = mocker.GetMock<Follower>();
            var mockCandidate = mocker.GetMock<Candidate>();
            var mockLeader = mocker.GetMock<Leader>();

            mocker.Setup<IObservableProvider>(p =>  p.GetObservable<Follower, ServerStateType>())
                .Returns(mockFollower.Object);

            mocker.Setup<IObservableProvider>(p => p.GetObservable<Candidate, ServerStateType>())
                .Returns(mockCandidate.Object);

            mocker.Setup<IObservableProvider>(p => p.GetObservable<Leader, ServerStateType>())
                .Returns(mockLeader.Object);

            Machine<ServerStateType, ServerStateType> machine = null;
            mocker.Setup<IHartbeatTimer>(p => p.Subscribe(It.IsAny<Machine<ServerStateType, ServerStateType>>()))
                .Returns(new Disposable())
                .Callback<Machine<ServerStateType, ServerStateType>>(m =>
                {
                    machine = m;
                });
            
            var node = new Node(mocker.Get<IVoteReceived>(),
                mocker.Get<IAppendEntry>(),
                mocker.Get<IHartbeatTimer>(),
                mocker.Get<ILoggerFactory>(),
                mocker.Get<IObservableProvider>(),
                mocker.Get<ILogReplication>(),
                mocker.Get<ServerIdentifier>());

            var mockHartbeat = mocker.GetMock<IHartbeatTimer>();

            // Assert
            Assert.Equal(ServerStateType.Follower, node.State);

            machine.OnNext(ServerStateType.Candidate);

            Assert.Equal(ServerStateType.Candidate, node.State);

            machine.OnNext(ServerStateType.Leader);
        }
        public void TestGetCloudantSecurityDocument_Should_Return_A_Valid_Document()
        {
            //SETUP
            var mocker = new AutoMocker();

            //connection returns base uri
            mocker.Setup<ICouchConnection>(c => c.BaseUri).Returns(new Uri("http://localhost"));

            //GetCouchResponse returns security doc as per Cloudant documentation
            const string responseString = "{ " +
                                          "\"_id\":\"_security\"," +
                                          "\"cloudant\":" +
                                          "{" +
                                          "  \"userwithreadonlyaccess\": [" +
                                          "    \"_reader\"" +
                                          "  ]," +
                                          "  \"userwithreadandwriteaccess\": [" +
                                          "    \"_reader\"," +
                                          "    \"_writer\"" +
                                          "  ]" +
                                          "}," +
                                          "\"ok\":true" +
                                          "}";
            mocker.Setup<ICouchResponse>(r => r.ResponseString).Returns(responseString);
            mocker.Setup<ICouchResponse, HttpStatusCode>(r => r.StatusCode).Returns(HttpStatusCode.OK);
            mocker.Setup<ICouchRequest>(r => r.GetCouchResponse()).Returns(mocker.Get<ICouchResponse>());

            //couchFactory returns request
            mocker.Setup<ICouchFactory>(f => f.GetRequest(It.IsAny<Uri>(), It.IsAny<ICouchConnection>()))
                .Returns(mocker.Get<ICouchRequest>());
            //Get request returns request
            mocker.Setup<ICouchRequest>(r => r.Get()).Returns(mocker.Get<ICouchRequest>());
            //Json content type returns request
            mocker.Setup<ICouchRequest>(r => r.Json()).Returns(mocker.Get<ICouchRequest>());

            //TEST
            var database = mocker.CreateInstance<CloudantDatabase>();

            var securityDocument = (CloudantSecurityDocument)database.GetSecurityDocument();

            securityDocument.Id.Should().Be("_security");
            securityDocument.CloudantSecuritySection.GetAssignment("userwithreadonlyaccess").Should().BeEquivalentTo("_reader");
            securityDocument.CloudantSecuritySection.GetAssignment("userwithreadandwriteaccess").Should().BeEquivalentTo("_reader", "_writer");
            securityDocument.Ok.Should().BeTrue();

            mocker.VerifyAll();
        }
        public void TestUpdateSecurityDoc_Should_Succeed_For_Valid_Document()
        {
            //SETUP
            var mocker = new AutoMocker();

            //connection returns base uri
            mocker.Setup<ICouchConnection>(c => c.BaseUri).Returns(new Uri("http://localhost"));

            //GetCouchResponse returns security doc as per Cloudant documentation
            const string responseString = "{ " +
                                          "\"ok\":true" +
                                          "}";
            mocker.Setup<ICouchResponse>(r => r.ResponseString).Returns(responseString);
            mocker.Setup<ICouchResponse, HttpStatusCode>(r => r.StatusCode).Returns(HttpStatusCode.OK);
            mocker.Setup<ICouchRequest>(r => r.GetCouchResponse()).Returns(mocker.Get<ICouchResponse>());

            //couchFactory returns request
            mocker.Setup<ICouchFactory>(f => f.GetRequest(It.IsAny<Uri>(), It.IsAny<ICouchConnection>()))
                .Returns(mocker.Get<ICouchRequest>());
            //Get request returns request
            mocker.Setup<ICouchRequest>(r => r.Put()).Returns(mocker.Get<ICouchRequest>());
            //Json content type returns request
            mocker.Setup<ICouchRequest>(r => r.Json()).Returns(mocker.Get<ICouchRequest>());
            //Data returns request
            mocker.Setup<ICouchRequest>(r => r.Data(It.IsAny<string>())).Returns(mocker.Get<ICouchRequest>());

            //security doc
            var securityDoc = new CloudantSecurityDocument();
            securityDoc.CloudantSecuritySection.AddUser("user1", "_reader");
            securityDoc.CloudantSecuritySection.AddUser("user2", "_reader","_writer");

            //TEST
            var database = mocker.CreateInstance<CloudantDatabase>();

            database.UpdateSecurityDocument(securityDoc);

            mocker.VerifyAll();
        }
        public void SubscribeTest()
        {
            var mocker = new AutoMocker();

            var serverIdentifier = new ServerIdentifier();

            mocker.Use(serverIdentifier);

            var options = new RaftOptions();
            options.Hartbeat.FromMilliseconds = 0;
            options.Hartbeat.ToMilliseconds = 0;

            var timer = new HartbeatTimer(options, mocker.Get<ILoggerFactory>(), serverIdentifier);
            var state = ServerStateType.Leader;

            timer.Subscribe((s) =>
            {
                state = s;    
            });

            Thread.Sleep(100);

            Assert.Equal(ServerStateType.Candidate, state);
        }
Beispiel #12
0
 public MimeTypesReaderTests()
 {
     _autoMocker = new AutoMocker();
 }
        public void TemplateType_AngularJsPrototype_Not_Found()
        {
            //Arrange
            AutoMocker mocker = new AutoMocker();
            var proxySettings = new ProxySettings();
            proxySettings.Templates.Add(new TemplateEntry() { TemplateType = TemplateTypes.AngularJsModule });

            mocker.Use<IProxyGeneratorFactoryManager>(new ProxyGeneratorFactoryManager(proxySettings));
            var myMock = mocker.CreateInstance<AngularJsProxyBuilder>();

            //Act
            var generatedProxyEntries = myMock.BuildProxy(new List<ProxyControllerInfo>());
        }
Beispiel #14
0
 public ResourceOpeningServiceOpenWithTests()
 {
     _autoMocker = new AutoMocker();
 }
Beispiel #15
0
 public MacApplicationServiceTests()
 {
     _autoMocker = new AutoMocker();
 }
Beispiel #16
0
 public FileSystemNodeViewModelFactoryTests()
 {
     _autoMocker = new AutoMocker();
 }
Beispiel #17
0
 public ProjectHandlerTest()
 {
     _mocker = new AutoMocker();
 }
 public LinuxTrashCanServiceTests()
 {
     _autoMocker = new AutoMocker();
 }
 public void SetUp()
 {
     _container = new AutoMocker();
     _container.Use(MockMyAccountUrlProviderFactory.Create());
     _container.Use(MockViewModelMapperFactory.Create(typeof(UpdateAccountViewModel).Assembly));
 }
 public MacMountedDriveServiceTests()
 {
     _autoMocker = new AutoMocker();
 }
Beispiel #21
0
 protected BaseAutoMock()
 {
     _mocker = new AutoMocker();
 }
Beispiel #22
0
        public void Then_Recalculates_The_Nemesis_For_The_Players_Who_Had_This_Current_Nemesis_Only()
        {
            //--arrange

            //--act
            AutoMocker.ClassUnderTest.DeletePlayer(PlayerId, CurrentUser);

            //--assert
            AutoMocker.Get <INemesisRecalculator>().AssertWasCalled(mock => mock.RecalculateNemesis(_playerIdWithCurrentNemesis, CurrentUser, AutoMocker.Get <IDataContext>()));
            AutoMocker.Get <INemesisRecalculator>().AssertWasCalled(mock => mock.RecalculateNemesis(_playerId2WithCurrentNemesis, CurrentUser, AutoMocker.Get <IDataContext>()));

            AutoMocker.Get <INemesisRecalculator>().AssertWasNotCalled(mock => mock.RecalculateNemesis(_playerIdWithPreviousNemesis, CurrentUser, AutoMocker.Get <IDataContext>()));
            AutoMocker.Get <INemesisRecalculator>().AssertWasNotCalled(mock => mock.RecalculateNemesis(_playerId2WithPreviousNemesis, CurrentUser, AutoMocker.Get <IDataContext>()));
        }
Beispiel #23
0
        public override void SetUp()
        {
            base.SetUp();
            SetupDefaultExpectations(setupPlayer: false, setupNemeses: false);

            var nemeses = new List <Nemesis>
            {
                new Nemesis
                {
                    NemesisPlayerId = PlayerId,
                    Id = _nemesisId1
                },
                new Nemesis
                {
                    NemesisPlayerId = PlayerId,
                    Id = _nemesisId2
                },
                new Nemesis
                {
                    NemesisPlayerId = PlayerId,
                    Id = _nemesisId3
                },
                new Nemesis
                {
                    NemesisPlayerId = PlayerId,
                    Id = _nemesisId4
                }
            };

            AutoMocker.Get <IDataContext>().Expect(m => m.GetQueryable <Nemesis>()).Return(nemeses.AsQueryable());

            var players = new List <Player>
            {
                new Player
                {
                    Id = PlayerId,
                    PlayerGameResults = new List <PlayerGameResult> ()
                },
                new Player
                {
                    Id        = _playerIdWithCurrentNemesis,
                    NemesisId = _nemesisId1
                },
                new Player
                {
                    Id        = _playerId2WithCurrentNemesis,
                    NemesisId = _nemesisId2
                },
                new Player
                {
                    Id = _playerIdWithPreviousNemesis,
                    PreviousNemesisId = _nemesisId3
                },
                new Player
                {
                    Id = _playerId2WithPreviousNemesis,
                    PreviousNemesisId = _nemesisId4
                }
            };

            AutoMocker.Get <IDataContext>().Expect(m => m.GetQueryable <Player>()).Return(players.AsQueryable());
        }
Beispiel #24
0
        public void Then_Recalculates_The_Champion_For_Each_Game_Championed()
        {
            //--act
            AutoMocker.ClassUnderTest.DeletePlayer(PlayerId, CurrentUser);

            //--assert
            AutoMocker.Get <IChampionRecalculator>().AssertWasCalled(mock => mock.RecalculateChampion(_gameDefinitionId, CurrentUser, AutoMocker.Get <IDataContext>()));
            AutoMocker.Get <IChampionRecalculator>().AssertWasCalled(mock => mock.RecalculateChampion(_gameDefinitionId2, CurrentUser, AutoMocker.Get <IDataContext>()));
        }
Beispiel #25
0
        public override void SetUp()
        {
            base.SetUp();
            SetupDefaultExpectations(setupChampions: false, setupPlayer: false);

            var players = new List <Player>
            {
                new Player
                {
                    Id = PlayerId,
                    PlayerGameResults = new List <PlayerGameResult>()
                },
                new Player
                {
                    Id = _playerIdForPreviousChampion,
                    PlayerGameResults = new List <PlayerGameResult>()
                }
            };

            AutoMocker.Get <IDataContext>().Expect(m => m.GetQueryable <Player>()).Return(players.AsQueryable());

            var champions = new List <Champion>
            {
                new Champion
                {
                    PlayerId = PlayerId,
                    Id       = _championId
                },
                new Champion
                {
                    PlayerId = PlayerId,
                    Id       = _championId2
                },
                new Champion
                {
                    PlayerId = -1
                },
                new Champion
                {
                    PlayerId = _playerIdForPreviousChampion,
                    Id       = _championIdForPreviousChamption
                }
            };

            AutoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Champion>()).Return(champions.AsQueryable());

            var gameDefinitions = new List <GameDefinition>
            {
                new GameDefinition
                {
                    ChampionId = _championId,
                    Id         = _gameDefinitionId
                },
                new GameDefinition
                {
                    Id         = _gameDefinitionId2,
                    ChampionId = _championId2
                },
                new GameDefinition
                {
                    PreviousChampionId = _championIdForPreviousChamption,
                    Id = _gameDefinitionIdForPreviousChampion
                }
            };

            AutoMocker.Get <IDataContext>()
            .Expect(mock => mock.GetQueryable <GameDefinition>())
            .Return(gameDefinitions.AsQueryable());
        }
 public ArchiveTypeViewModelFactoryTests()
 {
     _autoMocker = new AutoMocker();
 }
 public void SetUp()
 {
     _container = new AutoMocker();
 }
 public OpenWithApplicationServiceTests()
 {
     _autoMocker = new AutoMocker();
 }
Beispiel #29
0
 public ClassificationScoresForParticularRoundStrategyFactoryTests()
 {
     AutoFixture = new Fixture();
     Mocker      = new AutoMocker();
 }
 public GetAllHotelsHandlerTests()
 {
     AutoFixture = new Fixture();
     Mocker      = new AutoMocker();
 }
 public void SetUp()
 {
     _container = new AutoMocker();
     _container.Use((IFacetPredicateProviderRegistry) new FacetPredicateProviderRegistry());
     SetupFacets();
 }
        private static ContentFragment CreateFragment(string internalFormat)
        {
            var mocker = new AutoMocker();
            mocker.Use<TemplateModelSelector>(mocker.CreateInstance<TemplateModelSelector>());
            mocker.Use<DisplayChannelService>(mocker.CreateInstance<DisplayChannelService>());
            mocker.Use<TemplateModelRepository>(mocker.CreateInstance<TemplateModelRepository>());
            mocker.Use<TemplateResolver>(mocker.CreateInstance<TemplateResolver>());
            mocker.Use<TemplateControlLoader>(mocker.CreateInstance<TemplateControlLoader>());

            var fragment = new Mock<ContentFragment>(Mock.Of<IContentLoader>(), mocker.CreateInstance<TemplateControlLoader>(), Mock.Of<ISecuredFragmentMarkupGenerator>());
            fragment.SetupGet(x => x.InternalFormat).Returns(internalFormat);
            return fragment.Object;
        }
        public void It_Validates_Access_To_The_Players_In_The_Game()
        {
            //--arrange
            SetupExpectationsForExistingPlayedGame();

            int differentGameDefinitionId = _existingGameDefinitionId + 1;

            var updatedGame = new UpdatedGame
            {
                PlayedGameId     = _existingPlayedGameId,
                GameDefinitionId = differentGameDefinitionId
            };

            //--act
            AutoMocker.ClassUnderTest.UpdatePlayedGame(updatedGame, TransactionSource.RestApi, CurrentUser);

            //--assert
            AutoMocker.ClassUnderTest.AssertWasCalled(partialMock
                                                      => partialMock.ValidateAccessToPlayers(updatedGame.PlayerRanks, GAMING_GROUP_ID, CurrentUser, AutoMocker.Get <IDataContext>()));
        }
Beispiel #34
0
 public WindowsTerminalServiceTests()
 {
     _autoMocker = new AutoMocker();
 }
Beispiel #35
0
 public FilesPanelViewModelTests()
 {
     _autoMocker = new AutoMocker();
 }
            public void It_creates_mock_objects_for_ctor_parameters_with_supplied_behavior()
            {
                var strictMocker = new AutoMocker(MockBehavior.Strict);

                var instance = strictMocker.CreateInstance<OneConstructor>();
                var mock = Mock.Get(instance.Empty);
                mock.ShouldNotBeNull();
                mock.Behavior.ShouldEqual(MockBehavior.Strict);
            }
        public void It_Creates_The_Played_Game_Application_Linkages()
        {
            //--arrange
            SetupExpectationsForExistingPlayedGame();

            var updatedGame = new UpdatedGame
            {
                PlayedGameId        = _existingPlayedGameId,
                GameDefinitionId    = _existingGameDefinitionId,
                ApplicationLinkages = new List <ApplicationLinkage>
                {
                    new ApplicationLinkage()
                }
            };
            var transactionSource = TransactionSource.RestApi;

            //--act
            AutoMocker.ClassUnderTest.UpdatePlayedGame(updatedGame, transactionSource, CurrentUser);

            //--assert
            AutoMocker.ClassUnderTest.AssertWasCalled(mock => mock.CreateApplicationLinkages(updatedGame.ApplicationLinkages, _existingPlayedGameId, AutoMocker.Get <IDataContext>()));
        }
Beispiel #38
0
 public void SetUp()
 {
     _container = new AutoMocker();
     _container.Use(CreateDamProvider());
     _container.Use(CreateProductUrlProvider());
 }
        private void SetupExpectationsForExistingPlayedGame()
        {
            _existingPlayedGame = new PlayedGame
            {
                Id               = 1,
                GamingGroupId    = GAMING_GROUP_ID,
                GameDefinitionId = _existingGameDefinitionId,
                GameDefinition   = new GameDefinition
                {
                    BoardGameGeekGameDefinitionId = _existingBoardGameGeekGameDefinitionId
                },
                PlayerGameResults = new List <PlayerGameResult>
                {
                    new PlayerGameResult
                    {
                        Id = _existingPlayerGameResultId1
                    },
                    new PlayerGameResult
                    {
                        Id = _existingPlayerGameResultId2
                    }
                },
                ApplicationLinkages = new List <PlayedGameApplicationLinkage>
                {
                    new PlayedGameApplicationLinkage
                    {
                        Id = _existingPlayedGameApplicationLinkageId1
                    },
                    new PlayedGameApplicationLinkage
                    {
                        Id = _existingPlayedGameApplicationLinkageId2
                    }
                }
            };

            var playedGameQueryable = new List <PlayedGame>
            {
                _existingPlayedGame
            }.AsQueryable();

            AutoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <PlayedGame>()).Return(playedGameQueryable);

            AutoMocker.Get <ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess <GamingGroup>(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything))
            .Return(new GamingGroup());
            AutoMocker.Get <ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess <PlayedGame>(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything))
            .Return(new PlayedGame());
            AutoMocker.Get <ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess <GameDefinition>(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything))
            .Return(new GameDefinition());

            AutoMocker.ClassUnderTest.Expect(partialMock => partialMock.ValidateAccessToPlayers(
                                                 Arg <List <PlayerRank> > .Is.Anything,
                                                 Arg <int> .Is.Anything,
                                                 Arg <ApplicationUser> .Is.Anything,
                                                 Arg <IDataContext> .Is.Anything));

            _expectedNewPlayerGameResults = new List <PlayerGameResult>
            {
                new PlayerGameResult {
                    PlayerId = 10
                },
                new PlayerGameResult {
                    PlayerId = 11
                },
                new PlayerGameResult {
                    PlayerId = 12
                }
            };

            AutoMocker.ClassUnderTest.Expect(
                partialMock =>
                partialMock.MakePlayerGameResults(Arg <SaveableGameBase> .Is.Anything, Arg <int> .Is.Anything, Arg <IDataContext> .Is.Anything))
            .Return(_expectedNewPlayerGameResults);

            _expectedTransformedPlayedGame = new PlayedGame
            {
                Id = _existingPlayedGameId,
                GameDefinitionId = _existingGameDefinitionId
            };
            AutoMocker.ClassUnderTest.Expect(
                partialMock =>
                partialMock.TransformNewlyCompletedGameIntoPlayedGame(Arg <SaveableGameBase> .Is.Anything, Arg <int> .Is.Anything,
                                                                      Arg <string> .Is.Anything, Arg <List <PlayerGameResult> > .Is.Anything))
            .Return(_expectedTransformedPlayedGame);

            _expectedSavedPlayedGame = new PlayedGame();
            AutoMocker.Get <IDataContext>()
            .Expect(mock => mock.Save(Arg <PlayedGame> .Is.Anything, Arg <ApplicationUser> .Is.Anything))
            .Return(_expectedSavedPlayedGame);
        }
Beispiel #40
0
 public CachingConventionTests()
 {
     AutoFixture = new Fixture();
     Mocker      = new AutoMocker();
 }
Beispiel #41
0
 public AutomockerTestBase()
 {
     AutoMocker = new AutoMocker(MockBehavior.Strict);
 }
Beispiel #42
0
        protected ControllerTestsBase()
        {
            Mocker = new AutoMocker();

            Controller = Mocker.CreateInstance <T>();
        }
        public void It_Reconstructs_The_Played_Game_Then_Updates_It()
        {
            //--arrange
            SetupExpectationsForExistingPlayedGame();

            int differentGameDefinitionId = _existingGameDefinitionId + 1;

            var playerRank1 = new PlayerRank
            {
                PlayerId = 100,
                GameRank = 1
            };
            var playerRank2 = new PlayerRank
            {
                PlayerId = 101,
                GameRank = 1
            };
            var playerRank3 = new PlayerRank
            {
                PlayerId = 100,
                GameRank = 1
            };

            var updatedGame = new UpdatedGame
            {
                PlayedGameId     = _existingPlayedGameId,
                GameDefinitionId = differentGameDefinitionId,
                PlayerRanks      = new List <PlayerRank>
                {
                    playerRank1,
                    playerRank2,
                    playerRank3
                },
                DatePlayed = DateTime.UtcNow
            };

            //--act
            AutoMocker.ClassUnderTest.UpdatePlayedGame(updatedGame, TransactionSource.RestApi, CurrentUser);

            //--assert
            AutoMocker.ClassUnderTest.AssertWasCalled(
                partialMock =>
                partialMock.MakePlayerGameResults(updatedGame, _existingBoardGameGeekGameDefinitionId, AutoMocker.Get <IDataContext>()));

            AutoMocker.ClassUnderTest.AssertWasCalled(
                partialMock =>
                partialMock.TransformNewlyCompletedGameIntoPlayedGame(updatedGame, GAMING_GROUP_ID,
                                                                      CurrentUser.Id, _expectedNewPlayerGameResults));

            var arguments =
                AutoMocker.Get <IDataContext>()
                .GetArgumentsForCallsMadeOn(
                    x => x.Save(Arg <PlayedGame> .Is.Anything, Arg <ApplicationUser> .Is.Anything));

            arguments.ShouldNotBeNull();
            arguments.Count.ShouldBe(1);
            var actualPlayedGame = arguments[0][0] as PlayedGame;

            actualPlayedGame.ShouldNotBeNull();
            actualPlayedGame.DateUpdated.Date.ShouldBe(DateTime.UtcNow.Date);
            actualPlayedGame.Id.ShouldBe(updatedGame.PlayedGameId);
        }
Beispiel #44
0
 public void Setup()
 {
     mocker = new AutoMocker();
 }
Beispiel #45
0
 public TabsListViewModelTests()
 {
     _autoMocker = new AutoMocker();
 }
Beispiel #46
-1
        public LeaderBaseTests()
        {
            var mocker = new AutoMocker();

            ServerIdentifier = new ServerIdentifier();
            mocker.Use(ServerIdentifier);

            Election = new Election();
            AppendEntryResult = new Subject<AppendEntryResultMessage>();
            AppendEntry = new Subject<AppendEntryMessage>();
            LogReplication = new LogReplication();
            Nodes = new Nodes();

            Leader = new Rafting.States.Leader(
                Election,
                mocker.Get<IHartbeatTimer>(),
                AppendEntryResult,
                AppendEntry,
                mocker.Get<IObserver<ClientResultMessage>>(),
                mocker.Get<IObservable<ClientMessage>>(),
                LogReplication,
                Nodes,
                mocker.Get<ILoggerFactory>(),
                new RaftOptions(),
                mocker.Get<ServerIdentifier>());
        }