public void Setup() { mocks = new RhinoAutoMocker<Shelve>(); mocks.Inject<TextWriter>(new StringWriter()); mocks.Get<Globals>().Repository = mocks.Get<IGitRepository>(); mocks.MockObjectFactory(); }
public void SetUp() { _container = new RhinoAutoMocker<EntryPresenter>(); _systemUnderTest = _container.ClassUnderTest; _entryView = _container.Get<IEntryView>(); _repository = _container.Get<IRepository>(); _recentActivities = _container.Get<IRecentActivities>(); _recentActivities .Stub(x => x.First) .Return(ACTIVITY); _recentActivities .Stub(x => x.ToArray()) .Return(new[]{ ACTIVITY }); _entryView .Stub(x => x.Duration) .Return(DURATION); _entryView .Stub(x => x.Activity) .Return(ACTIVITY); _entryView.Stub(x => x.Note).Return(NOTE); _entryView.Raise(x => x.KeyDown += null, this, new KeyEventArgs(Keys.Enter)); }
public void SetUp() { var container = new RhinoAutoMocker<ApplicationController>(); var application = container.Get<IApplication>(); var hotKeySpecification = container.Get<IHotKeySpecification>(); var reportPesenter = container.Get<IReportPresenter>(); var keyboard = container.Get<IKeyboard>(); _presentationController = container.Get<IPresentationController>(); _keyboardEventArgs = new KeyboardEventArgs{Handled = false}; hotKeySpecification .Stub(spec => spec.IsSatisfiedBy(Arg<IKeyboard>.Is.Anything)) .Return(true); keyboard .Stub(x => x.AltPressed) .Return(true); keyboard .Stub(x => x.CtrlPressed) .Return(true); keyboard .Stub(x => x.ShiftPressed) .Return(true); keyboard .Stub(x => x.KeyPressed) .Return(VirtualKeyCode.VK_T); var systemUnderTest = container.ClassUnderTest; keyboard.Raise(x=>x.KeyDown += null, this, _keyboardEventArgs); }
public void TestSetUp() { autoMocker = new RhinoAutoMocker<PlayedGameSaver>(); autoMocker.PartialMockTheClassUnderTest(); currentUser = new ApplicationUser { Id = "user id", CurrentGamingGroupId = GAMING_GROUP_ID, AnonymousClientId = "anonymous client id" }; gameDefinition = new GameDefinition { Name = "game definition name", GamingGroupId = GAMING_GROUP_ID, Id = 9598 }; autoMocker.Get<ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess<GameDefinition>(Arg<int>.Is.Anything, Arg<ApplicationUser>.Is.Anything)).Return(gameDefinition); existingPlayerWithMatchingGamingGroup = new Player { Id = 1, GamingGroupId = GAMING_GROUP_ID }; autoMocker.Get<IDataContext>().Expect(mock => mock.FindById<Player>(Arg<int>.Is.Anything)).Return(existingPlayerWithMatchingGamingGroup); }
protected override void SetContext() { _mocks = new RhinoAutoMocker<CardReadyAction>(); _action = _mocks.ClassUnderTest; _cardService = _mocks.Get<ICardService>(); _card = _mocks.Get<Kokugen.Core.Domain.Card>(); }
public void SetUp() { _autoMocker = new RhinoAutoMocker<AuthTokenGenerator>(); _autoMocker.PartialMockTheClassUnderTest(); IAppSettings appSettingsMock = MockRepository.GenerateMock<IAppSettings>(); appSettingsMock.Expect(mock => mock[AuthTokenGenerator.APP_KEY_AUTH_TOKEN_SALT]).Return(_expectedSalt); _autoMocker.Get<IConfigurationManager>().Expect(mock => mock.AppSettings).Return(appSettingsMock); _autoMocker.ClassUnderTest.Expect(mock => mock.GenerateNewAuthToken()).Return(_expectedAuthToken); _autoMocker.ClassUnderTest.Expect(mock => mock.HashAuthToken(_expectedAuthToken)) .Return(_expectedSaltedHashedAuthToken); _applicationUser = new ApplicationUser { Id = ApplicationUserId }; _autoMocker.Get<IDataContext>().Expect(mock => mock.FindById<ApplicationUser>(Arg<string>.Is.Anything)).Return(_applicationUser); _userDeviceAuthTokenWithNoDeviceId = new UserDeviceAuthToken { Id = 0, ApplicationUserId = ApplicationUserId, DeviceId = null }; _userDeviceAuthTokenThatDoesntExpire = new UserDeviceAuthToken { Id = 1, ApplicationUserId = ApplicationUserId }; _userDeviceAuthTokenThatExpiresInTheFuture = new UserDeviceAuthToken { Id = 2, ApplicationUserId = ApplicationUserId, DeviceId = "device id for future expiration", AuthenticationTokenExpirationDate = DateTime.UtcNow.AddDays(1) }; _userDeviceAuthTokenThatExpiresInThePast = new UserDeviceAuthToken { Id = 3, ApplicationUserId = ApplicationUserId, DeviceId = "device id for already expired", AuthenticationTokenExpirationDate = DateTime.UtcNow.AddDays(-1) }; var authTokens = new List<UserDeviceAuthToken> { _userDeviceAuthTokenWithNoDeviceId, _userDeviceAuthTokenThatDoesntExpire, _userDeviceAuthTokenThatExpiresInTheFuture, _userDeviceAuthTokenThatExpiresInThePast, new UserDeviceAuthToken { ApplicationUserId = "some other applicationUserId" } }.AsQueryable(); _autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<UserDeviceAuthToken>()).Return(authTokens); }
public void Given_device_when_TheStockIsNotOutOfOrder_then_AddMethodShouldCalled() { var autoMocker = new RhinoAutoMocker<Machine>(); var device = new Device { ID = 1, Name = "printer" }; var product = autoMocker.Get<Iproduct>(); product.Stub(x => x.IsOutOfStock(Arg<Device>.Is.Anything)).Return(false); autoMocker.ClassUnderTest.RegisterNewDevice(device); autoMocker.Get<IDeviceManager>().AssertWasCalled(x => x.Add(device)); }
public void WhenNoRemotesFoundInParentCommits_AndThereIsOnlyOneRemoteInRepository_ThenThrowAnException() { var mocker = new RhinoAutoMocker<IGitRepository>(); var gitRepoMock = mocker.Get<IGitRepository>(); var globals = new Globals() { Bootstrapper = null, Repository = gitRepoMock }; globals.Repository.Stub(r => r.GetLastParentTfsCommits("HEAD")) .Return(new List<TfsChangesetInfo>()); globals.Repository.Stub(r => r.ReadAllTfsRemotes()) .Return(new List<GitTfsRemote>() { new GitTfsRemote(new RemoteInfo() { Id = "myRemote" }, gitRepoMock, new RemoteOptions(), globals, mocker.Get<ITfsHelper>(), new ConfigProperties(null)) }); Assert.Throws(typeof(GitTfsException), () => globals.RemoteId); }
public void WhenNoRemotesFoundInParentCommits_ThereIsOnlyOneRemoteInRepository_AndThisIsTheDefaultOne_ThenReturnIt() { var mocker = new RhinoAutoMocker<IGitRepository>(); var gitRepoMock = mocker.Get<IGitRepository>(); var globals = new Globals() { Bootstrapper = null, Repository = gitRepoMock }; globals.Repository.Stub(r => r.GetLastParentTfsCommits("HEAD")) .Return(new List<TfsChangesetInfo>()); globals.Repository.Stub(r => r.ReadAllTfsRemotes()) .Return(new List<GitTfsRemote>() { new GitTfsRemote(new RemoteInfo() { Id = "default" }, gitRepoMock, new RemoteOptions(), globals, mocker.Get<ITfsHelper>(), new ConfigProperties(null)) }); Assert.Equal("default", globals.RemoteId); }
public void SetUp() { autoMocker = new RhinoAutoMocker<AuthTokenValidator>(); const string EXPECTED_HASHED_AND_SALTED_AUTH_TOKEN = "some hashed and salted auth token"; autoMocker.Get<IAuthTokenGenerator>().Expect(mock => mock.HashAuthToken(this.validAuthToken)).Return( EXPECTED_HASHED_AND_SALTED_AUTH_TOKEN); _expectedUserDeviceAuthTokenThatIsntExpired = new UserDeviceAuthToken() { AuthenticationToken = EXPECTED_HASHED_AND_SALTED_AUTH_TOKEN, AuthenticationTokenExpirationDate = DateTime.UtcNow.AddDays(3) }; _applicationUserWithValidAuthToken = new ApplicationUser { UserDeviceAuthTokens = new List<UserDeviceAuthToken> { _expectedUserDeviceAuthTokenThatIsntExpired } }; const string EXPECTED_HASHED_AND_SALTED_AUTH_TOKEN_THAT_IS_EXPIRED = "some hashed and salted auth token that is expired"; autoMocker.Get<IAuthTokenGenerator>().Expect(mock => mock.HashAuthToken(this.expiredAuthToken)).Return( EXPECTED_HASHED_AND_SALTED_AUTH_TOKEN_THAT_IS_EXPIRED); _expectedUserDeviceAuthTokenThatIsExpired = new UserDeviceAuthToken() { AuthenticationToken = EXPECTED_HASHED_AND_SALTED_AUTH_TOKEN, AuthenticationTokenExpirationDate = DateTime.UtcNow.AddDays(-1) }; var applicationUserWithExpiredAuthToken = new ApplicationUser { UserDeviceAuthTokens = new List<UserDeviceAuthToken> { _expectedUserDeviceAuthTokenThatIsExpired } }; var applicationUsersQueryable = new List<ApplicationUser> { _applicationUserWithValidAuthToken, applicationUserWithExpiredAuthToken }.AsQueryable(); autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<ApplicationUser>()).Return(applicationUsersQueryable); }
public void Given_device_when_RegisterNewDevice_then_AddedSucessfullyShouldSetToTrue() { var autoMocker=new RhinoAutoMocker<Machine>(); var device=new Device {ID=1,Name = "printer"}; autoMocker.ClassUnderTest.RegisterNewDevice(device); autoMocker.Get<IDeviceManager>().AssertWasCalled(x => x.AddedSucessfully = true); }
public virtual void SetUp() { autoMocker = new RhinoAutoMocker<GameDefinitionController>(); autoMocker.Get<IGameDefinitionRetriever>() .Expect(mock => mock.GetTrendingGames(GameDefinitionController.NUMBER_OF_TRENDING_GAMES_TO_SHOW, GameDefinitionController.NUMBER_OF_DAYS_OF_TRENDING_GAMES)) .Return(trendingGames); AutomapperConfiguration.Configure(); urlHelperMock = MockRepository.GenerateMock<UrlHelper>(); autoMocker.ClassUnderTest.Url = urlHelperMock; asyncRequestMock = MockRepository.GenerateMock<HttpRequestBase>(); asyncRequestMock.Expect(x => x.Headers) .Repeat.Any() .Return(new System.Net.WebHeaderCollection { { "X-Requested-With", "XMLHttpRequest" } }); var context = MockRepository.GenerateMock<HttpContextBase>(); context.Expect(x => x.Request) .Repeat.Any() .Return(asyncRequestMock); autoMocker.ClassUnderTest.ControllerContext = new ControllerContext(context, new RouteData(), autoMocker.ClassUnderTest); currentUser = new ApplicationUser() { Id = "user id", CurrentGamingGroupId = 15151 }; }
public void Get_ReturnsTheFeatureInterestSummaryForTheGivenFeature() { string featureId = "some feature id"; VotableFeature expectedVotableFeature = new VotableFeature() { Id = featureId }; autoMocker.Get <IVotableFeatureRetriever>().Expect(mock => mock.RetrieveVotableFeature(featureId)) .Return(expectedVotableFeature); VotableFeatureViewModel expectedVotableFeatureViewModel = Mapper.Map <VotableFeature, VotableFeatureViewModel>(expectedVotableFeature); autoMocker.ClassUnderTest.Get(featureId); Assert.That(expectedVotableFeatureViewModel.Id, Is.EqualTo(featureId)); }
public void SetUpBase() { _autoMocker = new RhinoAutoMocker<PlayerSaver>(); _currentUser = new ApplicationUser { CurrentGamingGroupId = 12 }; _playerThatAlreadyExists = new Player { Name = "the new player name" }; _idOfPlayerThatAlreadyExists = 9; _players = new List<Player> { new Player { Id = _idOfPlayerThatAlreadyExists, Name = this._playerThatAlreadyExists.Name, GamingGroupId = _currentUser.CurrentGamingGroupId }, new Player { Id = 2 } }; _autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<Player>()) .Repeat.Once() .Return(_players.AsQueryable()); }
public void Before_first_test() { var mocker = new RhinoAutoMocker<ApplicationSettingsService>(); mocker.Get<ISystemService>() .Expect(x => x.AppDataDirectory) .Return(@"x:\temp"); _applicationSettings = new ApplicationSettings(); mocker.Get<ISerializationService>() .Expect(x => x.DeserializeFromFile<ApplicationSettings>(Arg<string>.Is.NotNull)) .Return(new Notification<ApplicationSettings> { Item = _applicationSettings }) .Repeat.Any(); _result = mocker.ClassUnderTest.Load(); }
public void WhenOnlyOneRemoteFoundInParentCommits_ThenReturnIt() { var mocker = new RhinoAutoMocker<IGitRepository>(); var gitRepoMock = mocker.Get<IGitRepository>(); var globals = new Globals() { Bootstrapper = null, Stdout = new StringWriter(), Repository = gitRepoMock }; globals.Repository.Stub(r => r.GetLastParentTfsCommits("HEAD")) .Return(new List<TfsChangesetInfo>() { new TfsChangesetInfo() { ChangesetId = 34, Remote = new GitTfsRemote(new RemoteInfo() {Id = "myRemote"}, gitRepoMock, new RemoteOptions(), globals, mocker.Get<ITfsHelper>(), new StringWriter()) } }); Assert.Equal("myRemote", globals.RemoteId); }
public void SetUp() { _autoMocker = new RhinoAutoMocker<ChampionRecalculator>(); _applicationUser = new ApplicationUser(); _gameDefinition = new GameDefinition { ChampionId = _previousChampionId }; _autoMocker.Get<IDataContext>().Expect(mock => mock.FindById<GameDefinition>(_gameDefinitionId)) .Return(_gameDefinition); _savedChampion = new Champion { Id = _newChampionId }; _autoMocker.Get<IDataContext>().Expect(mock => mock.Save(Arg<Champion>.Is.Anything, Arg<ApplicationUser>.Is.Anything)) .Return(_savedChampion); }
public void SetUp() { var services = new RhinoAutoMocker <SampleInputModel>(MockMode.AAA); var request = services.Get <IFubuRequest>(); _policies = new List <IValidationFailurePolicy>(); _handler = new ValidationFailureHandler(_policies, request); }
public void BeforeEachTest() { _firstInput = 0; _secondInput = 0; var mocker = new RhinoAutoMocker<Calculator>(); _calculator = mocker.ClassUnderTest; _storageService = mocker.Get<IStorageService>(); }
public void Test() { // Arrange var autoMocker = new RhinoAutoMocker <MyClassAuto>(); autoMocker.Get <IGreetingService>().Stub(x => x.Greet("A Name")); autoMocker.Get <INameProvider>().Expect(x => x.GetName()).Return("A Name"); // Act var sut = autoMocker.ClassUnderTest; sut.DoGreeting(); // Assert autoMocker.Get <INameProvider>().VerifyAllExpectations(); autoMocker.Get <IGreetingService>().AssertWasCalled(x => x.Greet("A Name")); }
public void SetUp() { _mocker = new RhinoAutoMocker<UserController>(); _userRepository = _mocker.Get<IUserRepository>(); _userMapper = _mocker.Get<IMapper<UserEditViewModel, User>>(); _userController = _mocker.ClassUnderTest; const string userId = "Test"; _userEditModel = new UserEditViewModel { UserId = userId }; _user = new User { UserId = userId }; }
public void WhenUserSpecifyARemote_ThenReturnIt() { var mocker = new RhinoAutoMocker<IGitRepository>(); var gitRepoMock = mocker.Get<IGitRepository>(); var globals = new Globals() { Bootstrapper = null, Stdout = new StringWriter(), Repository = gitRepoMock }; globals.UserSpecifiedRemoteId = "IWantThatRemote"; Assert.Equal("IWantThatRemote", globals.RemoteId); }
public void It_Returns_A_404_If_The_Player_Doesnt_Have_The_Achievement() { //--arrange var achievementId = AchievementId.BusyBee; int playerId = -1; var playerAchievementQuery = new PlayerAchievementQuery(achievementId, playerId); _autoMocker.Get <IPlayerAchievementRetriever>().Expect(mock => mock.GetPlayerAchievement(playerAchievementQuery)) .IgnoreArguments() .Return(null); //--act var result = _autoMocker.ClassUnderTest.PlayerAchievement(achievementId, playerId); //--assert result.ShouldBeAssignableTo <HttpNotFoundResult>(); }
public async Task ItReturnsAnHttp401NotAuthorizedResponseIfTheUsernameAndPasswordIsNotValid() { var credentialsMessage = new CredentialsMessage { UserName = "******", Password = "******" }; autoMocker.Get <ApplicationUserManager>().Expect(mock => mock.FindAsync( Arg <string> .Matches(userName => userName == credentialsMessage.UserName), Arg <string> .Matches(password => password == credentialsMessage.Password))) .Return(Task.FromResult((ApplicationUser)null)); var actualResponse = await autoMocker.ClassUnderTest.Login(credentialsMessage); AssertThatApiAction.HasThisError(actualResponse, HttpStatusCode.Unauthorized, "Invalid credentials provided."); }
public void ItUpdatesTheAspNetUsersAuthenticationTokenWithAHashedAndSaltedToken() { autoMocker.PartialMockTheClassUnderTest(); const string expectedAuthToken = "some auth token"; autoMocker.ClassUnderTest.Expect(mock => mock.GenerateNewAuthToken()).Return(expectedAuthToken); const string expectedSaltedHashedAuthToken = "some salted hashed auth token"; autoMocker.ClassUnderTest.Expect(mock => mock.HashAuthToken(expectedAuthToken)) .Return(expectedSaltedHashedAuthToken); autoMocker.ClassUnderTest.GenerateAuthToken(applicationUserId); autoMocker.Get <IDataContext>().AssertWasCalled(mock => mock.Save(Arg <ApplicationUser> .Matches(user => user.Id == applicationUserId && user.AuthenticationToken == expectedSaltedHashedAuthToken), Arg <ApplicationUser> .Is.Anything)); }
public void ItReturnsAnEmptyListIfThereAreNoSearchResults() { autoMocker = new RhinoAutoMocker <PlayedGameRetriever>(); autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <PlayedGame>()).Return(new List <PlayedGame>().AsQueryable()); var results = autoMocker.ClassUnderTest.SearchPlayedGames(new PlayedGameFilter()); Assert.That(results.Count, Is.EqualTo(0)); }
public void ItAwardsBonusPointsForGameWeight() { //--arrange var bggGameDefinition = new BoardGameGeekGameDefinition { AverageWeight = WeightTierCalculator.BOARD_GAME_GEEK_WEIGHT_INCLUSIVE_LOWER_BOUND_FOR_EASY - (decimal)0.01 }; //--act _autoMocker.ClassUnderTest.CalculatePoints(new List <PlayerRank>(), bggGameDefinition); //--assert _autoMocker.Get <IWeightBonusCalculator>().AssertWasCalled( mock => mock.CalculateWeightBonus(Arg <Dictionary <int, PointsScorecard> > .Is.Anything, Arg <decimal?> .Is.Equal(bggGameDefinition.AverageWeight))); }
public void SetUp() { var services = new RhinoAutoMocker<SampleInputModel>(MockMode.AAA); var request = services.Get<IFubuRequest>(); _policies = new List<IValidationFailurePolicy>(); _handler = new ValidationFailureHandler(_policies, request); }
public void WhenCertainNumberOfOrdersExist_ShouldReturnOKWithCountEqualToSameNumberOfOrders() { // arrange var ordersCountParameters = new OrdersCountParametersModel(); var autoMocker = new RhinoAutoMocker <OrdersController>(); autoMocker.Get <IJsonFieldsSerializer>().Stub(x => x.Serialize(null, null)).Return(string.Empty); autoMocker.Get <IOrderApiService>().Stub(x => x.GetOrdersCount()).IgnoreArguments().Return(20000); // act IHttpActionResult result = autoMocker.ClassUnderTest.GetOrdersCount(ordersCountParameters); // assert Assert.IsInstanceOf <OkNegotiatedContentResult <OrdersCountRootObject> >(result); Assert.AreEqual(20000, ((OkNegotiatedContentResult <OrdersCountRootObject>)result).Content.Count); }
public void WhenNoCategoriesExist_ShouldCallTheSerializerWithRootObjectWithoutCategories() { var parameters = new CategoriesParametersModel(); //Arange var autoMocker = new RhinoAutoMocker <CategoriesController>(); autoMocker.Get <ICategoryApiService>().Stub(x => x.GetCategories()).Return(new List <Category>()); //Act autoMocker.ClassUnderTest.GetCategories(parameters); //Assert autoMocker.Get <IJsonFieldsSerializer>().AssertWasCalled( x => x.Serialize(Arg <CategoriesRootObject> .Matches(r => r.Categories.Count == 0), Arg <string> .Is.Equal(parameters.Fields))); }
public void Before_first_test() { var mocker = new RhinoAutoMocker <ApplicationSettingsService>(); mocker.Get <ISystemService>() .Expect(x => x.AppDataDirectory) .Return(@"x:\temp"); _applicationSettings = new ApplicationSettings(); mocker.Get <ISerializationService>() .Expect(x => x.DeserializeFromFile <ApplicationSettings>(Arg <string> .Is.NotNull)) .Return(new Notification <ApplicationSettings> { Item = _applicationSettings }) .Repeat.Any(); _result = mocker.ClassUnderTest.Load(); }
public void SetUp() { _autoMocker = new RhinoAutoMocker <ChampionRecalculator>(); _applicationUser = new ApplicationUser(); _gameDefinition = new GameDefinition { ChampionId = _previousChampionId }; _autoMocker.Get <IDataContext>().Expect(mock => mock.FindById <GameDefinition>(_gameDefinitionId)) .Return(_gameDefinition); _savedChampion = new Champion { Id = _newChampionId }; _autoMocker.Get <IDataContext>().Expect(mock => mock.Save(Arg <Champion> .Is.Anything, Arg <ApplicationUser> .Is.Anything)) .Return(_savedChampion); }
public void BeforeEachTest() { var mocker = new RhinoAutoMocker <MainPresenter>(); _mainPresenter = mocker.ClassUnderTest; _accountService = mocker.Get <IAccountService>(); _account = MockRepository.GenerateStub <IAccount>(); }
public void Setup() { _container = new RhinoAutoMocker<EntryPresenter>(); _systemUnderTest = _container.ClassUnderTest; _entryView = _container.Get<IEntryView>(); _entryView.Raise(x => x.KeyDown += null, this, new KeyEventArgs(Keys.Escape)); }
public void ItFiltersPlayedGamesThatHappenedAfterTheToDate() { var autoMocker = new RhinoAutoMocker <PlayerRetriever>(); autoMocker.PartialMockTheClassUnderTest(); var gamingGroupId = 1; var toDate = new DateTime(2015, 1, 1); var expectedNemePointsAwardedForEachGame = 50; var queryable = new List <Player> { new Player { GamingGroupId = gamingGroupId, PlayerGameResults = new List <PlayerGameResult> { new PlayerGameResult { GameRank = 2, PlayedGame = new PlayedGame { DatePlayed = toDate.AddDays(-1) }, NemeStatsPointsAwarded = expectedNemePointsAwardedForEachGame }, new PlayerGameResult { GameRank = 1, PlayedGame = new PlayedGame { DatePlayed = toDate.AddDays(1) }, NemeStatsPointsAwarded = expectedNemePointsAwardedForEachGame } }, ChampionedGames = new List <Champion>() } }.AsQueryable(); autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>()) .Return(queryable); autoMocker.ClassUnderTest.Expect(mock => mock.PopulateNemePointsSummary(Arg <int> .Is.Anything, Arg <List <PlayerWithNemesis> > .Is.Anything, Arg <IDateRangeFilter> .Is.Anything)); var dateRangeFilter = new BasicDateRangeFilter { ToDate = toDate }; var players = autoMocker.ClassUnderTest.GetAllPlayersWithNemesisInfo(gamingGroupId, dateRangeFilter); Assert.That(players.Count, Is.EqualTo(1)); var player = players.First(); Assert.That(player.GamesLost, Is.EqualTo(1)); Assert.That(player.GamesWon, Is.EqualTo(0)); }
public void It_Returns_Recent_Champion_Changes_Ordered_By_Champion_Created_Date_Descending() { //--arrange var gameDefinitionThatMatchesWithOlderDate = MakeValidGameDefinition(2); gameDefinitionThatMatchesWithOlderDate.Champion.DateCreated = DateTime.UtcNow.Date.AddDays(-1 * 100); gameDefinitionThatMatchesWithOlderDate.Champion.PlayerId = 20; var gameDefinitionThatMatchesWithNewerDate = MakeValidGameDefinition(1); var queryable = new List <GameDefinition> { gameDefinitionThatMatchesWithOlderDate, gameDefinitionThatMatchesWithNewerDate }.AsQueryable(); _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <GameDefinition>()) .Return(queryable); var filter = new GetRecentChampionChangesFilter(GAMING_GROUP_ID, 100); //--act var results = _autoMocker.ClassUnderTest.GetRecentChampionChanges(filter); //--assert results.ShouldNotBeNull(); results.Count.ShouldBe(2); //--first result is the newest results[0].DateCreated.Date.ShouldBe(gameDefinitionThatMatchesWithNewerDate.Champion.DateCreated); results[0].GameDefinitionId.ShouldBe(gameDefinitionThatMatchesWithNewerDate.Id); results[0].GameName.ShouldBe(gameDefinitionThatMatchesWithNewerDate.Name); results[0].NewChampionPlayerId.ShouldBe(gameDefinitionThatMatchesWithNewerDate.Champion.PlayerId); results[0].NewChampionPlayerName.ShouldBe(gameDefinitionThatMatchesWithNewerDate.Champion.Player.Name); results[0].PreviousChampionPlayerId.ShouldBe(gameDefinitionThatMatchesWithNewerDate.PreviousChampion.PlayerId); results[0].PreviousChampionPlayerName.ShouldBe(gameDefinitionThatMatchesWithNewerDate.PreviousChampion.Player.Name); //--second result is the oldest results[1].DateCreated.Date.ShouldBe(gameDefinitionThatMatchesWithOlderDate.Champion.DateCreated); results[1].GameDefinitionId.ShouldBe(gameDefinitionThatMatchesWithOlderDate.Id); results[1].GameName.ShouldBe(gameDefinitionThatMatchesWithOlderDate.Name); results[1].NewChampionPlayerId.ShouldBe(gameDefinitionThatMatchesWithOlderDate.Champion.PlayerId); results[1].NewChampionPlayerName.ShouldBe(gameDefinitionThatMatchesWithOlderDate.Champion.Player.Name); results[1].PreviousChampionPlayerId.ShouldBe(gameDefinitionThatMatchesWithOlderDate.PreviousChampion.PlayerId); results[1].PreviousChampionPlayerName.ShouldBe(gameDefinitionThatMatchesWithOlderDate.PreviousChampion.Player.Name); }
public void It_Validates_The_User_Has_Access_To_The_Specified_Gaming_Group_Id() { //--arrange var newlyCompletedPlayedGame = CreateValidNewlyCompletedGame(); newlyCompletedPlayedGame.GamingGroupId = GAMING_GROUP_ID; _currentUser.CurrentGamingGroupId = 42; //--act _autoMocker.ClassUnderTest.Execute(newlyCompletedPlayedGame, _currentUser, _dataContext); //--assert _autoMocker.Get <ISecuredEntityValidator>().AssertWasCalled(mock => mock.RetrieveAndValidateAccess <GamingGroup>(newlyCompletedPlayedGame.GamingGroupId.Value, _currentUser)); }
public void Before_first_test() { var mocker = new RhinoAutoMocker<StorageService>(); mocker.Get<IApplicationSettingsService>() .Expect(x => x.Load()) .Return(new Notification<ApplicationSettings> { Item = new ApplicationSettings { StatementPath = @"x:\test.statement" } }) .Repeat.Any(); mocker.Get<ISerializationService>() .Expect(x => x.SerializeToFile(Arg<Statement>.Is.NotNull, Arg<string>.Is.NotNull)) .Return(Notification.ErrorFor("pretend")); _result = mocker.ClassUnderTest.Save(new Statement()); }
public void Before_first_test() { var mocker = new RhinoAutoMocker <SerializationService>(); mocker.Get <IJsonSerializer>() .Expect(x => x.DeserializeFromFile <TestObject>(Arg <string> .Is.NotNull)) .Throw(new Exception("pretend")); _service = mocker.ClassUnderTest; }
public void SetUp() { var services = new RhinoAutoMocker<SampleInputModel>(MockMode.AAA); var request = services.Get<IFubuRequest>(); _context = new ValidationFailure(ActionCall.For<SampleInputModel>(m => m.Test("Hello")), Notification.Valid(), "Hello"); _policies = new List<IValidationFailurePolicy>(); _handler = new ValidationFailureHandler(_policies, request); }
public void ItReturnsTheItemFromTheCacheIfItExists() { //--arrange int inputValue = 1; var cacheKey = _autoMocker.ClassUnderTest.GetCacheKey(inputValue); var playerStatisticsIncache = new PlayerStatistics(); _autoMocker.Get <ICacheService>().Expect(mock => mock.TryGetItemFromCache( Arg <string> .Is.Equal(cacheKey), out Arg <PlayerStatistics> .Out(playerStatisticsIncache).Dummy)) .Return(true); //--act var results = _autoMocker.ClassUnderTest.GetResults(inputValue); //--assert Assert.That(results, Is.SameAs(playerStatisticsIncache)); }
public void Connect_IsCalledOn_Login_WhenPassedValidInput() { // ARRANGE var autoMocker = new RhinoAutoMocker <LoginService>(); var settings = new LdapSettingsService(); settings.Username = "******"; settings.Password = "******"; autoMocker.Get <ILdapServerConnection>().Stub(connection => connection.Connect(Arg <ILdapSettingsService> .Is.TypeOf)); // ACT autoMocker.ClassUnderTest.Login(settings); // ASSERT autoMocker.Get <ILdapServerConnection>().AssertWasCalled(connection => connection.Connect(Arg <ILdapSettingsService> .Is.TypeOf)); }
public void IsAuthenticated_IsSetToTrueIf_ConnectionIsAuthenticated() { // ARRANGE var autoMocker = new RhinoAutoMocker <LoginService>(); var settings = new LdapSettingsService(); settings.Username = "******"; settings.Password = "******"; autoMocker.Get <ILdapServerConnection>().Stub(c => c.IsAuthenticated).Return(true); // ACT autoMocker.ClassUnderTest.Login(settings); // ASSERT autoMocker.Get <ILdapServerConnection>().AssertWasCalled(c => c.IsAuthenticated); }
public void SetUp() { _mocker = new RhinoAutoMocker <UserController>(); _userRepository = _mocker.Get <IUserRepository>(); _userMapper = _mocker.Get <IMapper <UserEditViewModel, User> >(); _userController = _mocker.ClassUnderTest; const string userId = "Test"; _userEditModel = new UserEditViewModel { UserId = userId }; _user = new User { UserId = userId }; }
public void WhenSomeValidParametersPassed_ShouldCallTheServiceWithTheSameParameters() { var parameters = new ShoppingCartItemsParametersModel(); //Arange var autoMocker = new RhinoAutoMocker <ShoppingCartItemsController>(); autoMocker.Get <IShoppingCartItemApiService>().Expect(x => x.GetShoppingCartItems(null, parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.UpdatedAtMin, parameters.UpdatedAtMax, parameters.Limit, parameters.Page)).Return(new List <ShoppingCartItem>()); //Act autoMocker.ClassUnderTest.GetShoppingCartItems(parameters); //Assert autoMocker.Get <IShoppingCartItemApiService>().VerifyAllExpectations(); }
public void SetUp() { autoMocker = new RhinoAutoMocker <GameDefinitionRetriever>(); currentUser = new ApplicationUser() { Id = "user id", CurrentGamingGroupId = gamingGroupId }; var gameDefinitions = new List <GameDefinition>() { new GameDefinition() { Id = 1, Active = true, GamingGroupId = gamingGroupId, PlayedGames = new List <PlayedGame>() }, new GameDefinition() { Id = 2, Active = false, GamingGroupId = gamingGroupId, PlayedGames = new List <PlayedGame>() }, new GameDefinition() { Id = 3, Active = true, GamingGroupId = -1, PlayedGames = new List <PlayedGame>(), Champion = new Champion { Player = new Player { Id = CHAMPION_ID } }, PreviousChampion = new Champion() { Player = new Player { Id = PREVIOUS_CHAMPION_ID } } } }; gameDefinitionQueryable = gameDefinitions.AsQueryable(); var players = new List <Player> { new Player { Id = CHAMPION_ID }, new Player { Id = PREVIOUS_CHAMPION_ID } }; autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>()).Return(players.AsQueryable()); }
public void SetUp() { _autoMocker = new RhinoAutoMocker <UniversalGameRetriever>(); _currentUser = new ApplicationUser { Id = "some user id", CurrentGamingGroupId = 1 }; _expectedGameDefinition = new GameDefinition { Id = 20, BoardGameGeekGameDefinitionId = _boardGameGeekGameDefinitionId, GamingGroupId = _currentUser.CurrentGamingGroupId.Value }; var otherGameDefinition = new GameDefinition { Id = 21, BoardGameGeekGameDefinitionId = _boardGameGeekGameDefinitionId }; var gameDefinitionQueryable = new List <GameDefinition> { _expectedGameDefinition, otherGameDefinition }.AsQueryable(); _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <GameDefinition>()).Return(gameDefinitionQueryable); _expectedBoardGameGeekInfo = new BoardGameGeekInfo(); _autoMocker.Get <IBoardGameGeekGameDefinitionInfoRetriever>().Expect(mock => mock.GetResults(Arg <int> .Is.Anything)).Return(_expectedBoardGameGeekInfo); _expectedGameDefinitionSummary = new GameDefinitionSummary(); _expectedUniversalStats = new UniversalGameStats(); _autoMocker.Get <IUniversalStatsRetriever>().Expect(mock => mock.GetResults(Arg <int> .Is.Anything)) .Return(_expectedUniversalStats); _expectedTopChampions = new List <ChampionData>(); _autoMocker.Get <IUniversalTopChampionsRetreiver>().Expect(mock => mock.GetFromSource(Arg <int> .Is.Anything)) .Return(_expectedTopChampions); }
public void It_Returns_The_BoardGameGeekInfo() { //--arrange //--act var result = _autoMocker.ClassUnderTest.GetBoardGameGeekGameSummary(_boardGameGeekGameDefinitionId, _currentUser); //--assert _autoMocker.Get <IBoardGameGeekGameDefinitionInfoRetriever>().AssertWasCalled(mock => mock.GetResults(_boardGameGeekGameDefinitionId)); result.BoardGameGeekInfo.ShouldBeSameAs(_expectedBoardGameGeekInfo); }
public void ItDoesntCreateANewRecordIfOneAlreadyExists() { autoMocker.Get <IDataContext>().Expect(mock => mock.FindById <BoardGameGeekGameDefinition>(boardGameGeekGameDefinitionId)) .Return(new BoardGameGeekGameDefinition()); autoMocker.ClassUnderTest.CreateBoardGameGeekGameDefinition(boardGameGeekGameDefinitionId, currentUser); autoMocker.Get <IDataContext>().AssertWasNotCalled(mock => mock.Save( Arg <BoardGameGeekGameDefinition> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); }
public void SetUp() { _autoMocker = new RhinoAutoMocker<UniversalGameRetriever>(); _gameWithNoPlays = new BoardGameGeekGameDefinition { Id = 2, DateCreated = DateTime.UtcNow.AddYears(-5), GameDefinitions = new List<GameDefinition> { new GameDefinition { } } }; _gameWithPlays = new BoardGameGeekGameDefinition { Id = 1, GameDefinitions = new List<GameDefinition> { new GameDefinition { PlayedGames = new List<PlayedGame> { new PlayedGame { DatePlayed = _mostRecentPlayedGame.AddDays(-4) } } }, new GameDefinition { PlayedGames = new List<PlayedGame> { new PlayedGame { DatePlayed = _mostRecentPlayedGame.AddDays(-3) }, new PlayedGame { DatePlayed = _mostRecentPlayedGame } } } } }; var queryable = new List<BoardGameGeekGameDefinition> { _gameWithNoPlays, _gameWithPlays }.AsQueryable(); _autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<BoardGameGeekGameDefinition>()).Return(queryable); }
public void IfInstallPackageCallsPowershellRun() { var powershell = _mocks.Get <IRunAsync>(); var sourceService = _mocks.Get <ISourceService>(); sourceService.Expect(x => x.Source) .Return(new Source { Url = "test" }); _service.InstallPackage("test"); powershell.AssertWasCalled(mock => mock.Run("cinst test -source test")); }
public void Before_first_test() { var mocker = new RhinoAutoMocker <SerializationService>(); mocker.Get <IJsonSerializer>() .Expect(x => x.DeserializeFromFile <TestObject>(Arg <string> .Is.NotNull)) .Return(_objToReturn) .Repeat.Any(); _service = mocker.ClassUnderTest; }
public void Setup() { _container = new RhinoAutoMocker<PresentationController>(); var systemUnderTest = _container.ClassUnderTest; _container .Get<INotifyIcon>() .Raise(x => x.ShowReport += null, this, EventArgs.Empty); }
public virtual void SetUp() { rollbarclient = MockRepository.GenerateStub<IRollbarClient>(); autoMocker = new RhinoAutoMocker<BoardGameGeekBatchUpdateJobService>(); autoMocker.Inject(typeof(IRollbarClient), rollbarclient); autoMocker.Get<IDataContext>() .Expect(mock => mock.GetQueryable<GameDefinition>()) .Return(OrphanGames.AsQueryable()); }
public void WhenNoCustomersExist_ShouldCallTheSerializerWithNoCustomers() { var returnedCustomersDtoCollection = new List <CustomerDto>(); var parameters = new CustomersParametersModel(); //Arange var autoMocker = new RhinoAutoMocker <CustomersController>(); autoMocker.Get <ICustomerApiService>().Stub(x => x.GetCustomersDtos()).Return(returnedCustomersDtoCollection); //Act autoMocker.ClassUnderTest.GetCustomers(parameters); //Assert autoMocker.Get <IJsonFieldsSerializer>().AssertWasCalled( x => x.Serialize(Arg <CustomersRootObject> .Matches(r => r.Customers.Count == returnedCustomersDtoCollection.Count), Arg <string> .Is.Equal(parameters.Fields))); }
public void ItFiltersOutInvalidResults() { //--arrange var playerGameResults = MakePlayerGameResults(_playerId, 3); //--wrong dates playerGameResults[0].PlayedGame.DatePlayed = new DateTime(2016, 12, 23); playerGameResults[1].PlayedGame.DatePlayed = new DateTime(2016, 1, 2); //--wrong player playerGameResults[2].PlayerId = -1; _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <PlayerGameResult>()).Return(playerGameResults.AsQueryable()); //--act var results = _autoMocker.ClassUnderTest.IsAwardedForThisPlayer(_playerId); //--assert Assert.That(results.LevelAwarded, Is.Null); }
public void SetUp() { _autoMocker = new RhinoAutoMocker<UniversalGameRetriever>(); _currentUser = new ApplicationUser { Id = "some user id" }; _expectedGameDefinition = new GameDefinition { Id = 20, BoardGameGeekGameDefinitionId = _boardGameGeekGameDefinitionId, }; var otherGameDefinition = new GameDefinition { Id = 21, BoardGameGeekGameDefinitionId = _boardGameGeekGameDefinitionId, }; var gameDefinitionQueryable = new List<GameDefinition> { _expectedGameDefinition, otherGameDefinition }.AsQueryable(); _autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<GameDefinition>()).Return(gameDefinitionQueryable); _expectedBoardGameGeekInfo = new BoardGameGeekInfo(); _autoMocker.Get<IBoardGameGeekGameDefinitionInfoRetriever>().Expect(mock => mock.GetResults(Arg<int>.Is.Anything)).Return(_expectedBoardGameGeekInfo); _expectedGameDefinitionSummary = new GameDefinitionSummary(); _expectedUniversalStats = new UniversalGameStats(); _autoMocker.Get<IUniversalStatsRetriever>().Expect(mock => mock.GetResults(Arg<int>.Is.Anything)) .Return(_expectedUniversalStats); _expectedTopChampions = new List<ChampionData>(); _autoMocker.Get<IUniversalTopChampionsRetreiver>().Expect(mock => mock.GetFromSource(Arg<int>.Is.Anything)) .Return(_expectedTopChampions); }
public void SetUp() { _container = new RhinoAutoMocker<RecentActivities>(); _recentActivities = _container.ClassUnderTest; _container.Get<IRepository>() .Stub(x=>x.AllInstances<Entry>()) .Return(new List<Entry>().AsQueryable()); _recentActivities.Add(FIRST_ACTIVITY); }
public void WhenNoRemotesFoundInParentCommits_AndNoRemotesInRepository_ThenReturnDefaultOne() { var mocker = new RhinoAutoMocker<IGitRepository>(); var gitRepoMock = mocker.Get<IGitRepository>(); var globals = new Globals() { Bootstrapper = null, Stdout = new StringWriter(), Repository = gitRepoMock }; globals.Repository.Stub(r => r.GetLastParentTfsCommits("HEAD")) .Return(new List<TfsChangesetInfo>()); globals.Repository.Stub(r => r.ReadAllTfsRemotes()) .Return(new List<GitTfsRemote>()); Assert.Equal("default", globals.RemoteId); }
public void SetUp() { autoMocker = new RhinoAutoMocker<VotableFeatureVoter>(MockMode.AAA); expectedVotableFeature = new VotableFeature { NumberOfDownvotes = startingNumberOfDownvotes, NumberOfUpvotes = startingNumberOfUpvotes }; autoMocker.Get<IDataContext>().Expect(mock => mock.FindById<VotableFeature>(votableFeatureId)) .Return(expectedVotableFeature); }