public void Setup()
		{
            product = new Product
            {
                Reviews =
                    {
                        new Review(),
                        new Review()
                    }
            };

            productRepository = new FakeRepository<Product>(id =>
            {
                product.Id = id;
                return product;
            });

            reviewRepository = MockRepositoryBuilder.CreateReviewRepository();

            commentRepository = MockRepository.GenerateStub<IRepository<IComment>>();

            var comments = new List<IComment>
	        {
                new Comment{ Approved = true },
                new Comment{ Approved = false },
                new Review{ Approved = true },
                new Comment{ Approved = true }
	        }.AsQueryable();
            commentRepository.Stub(r => r.GetAll()).Return(comments);

            controller = new ReviewsController(reviewRepository, productRepository, commentRepository);
		}
Esempio n. 2
0
        public void Before_Each_Test()
        {
            console = MockRepository.GenerateMock<IConsoleFacade>();
            repository = MockRepository.GenerateMock<IRepository<GameObject>>();
            player = MockRepository.GenerateMock<IPlayer>();

            dbPlayer = new GameObject() { GameObjectId = 3, Location = dbHallway, Location_Id = 8, Description = "Just some dude." };
            player.Stub(qq => qq.Id).Return(3);
            dbHallway = new GameObject() { Name = "Hallway", Description = " It's a hallway", GameObjectId = 8 };
            dbBall = new GameObject() { Name = "Ball", Description = "A shiny rubber ball", Location = dbPlayer, Location_Id = 3 };
            dbRing = new GameObject() { Name = "Ring", Description = "A simple gold ring", Location = dbHallway, Location_Id = 8 };
            dbExit = new GameObject() {Name = "Exit", Description ="", Location= dbHallway, Location_Id = 8, GameObjectId = 16, Type = "Exit", Destination = 8 };

            dbPlayer.Inventory.Add(dbBall);
            dbHallway.Inventory.Add(dbPlayer);
            dbHallway.Inventory.Add(dbRing);
            dbHallway.Inventory.Add(dbExit);
            dbList = new List<GameObject>() { dbPlayer, dbBall, dbRing, dbExit, dbHallway };
            repository.Stub(qq => qq.AsQueryable()).Return(dbList.AsQueryable());

            exit = new ExitAlias() { AliasId = 2, ExitId = 16, Alais = "North" };
            exit2 = new ExitAlias() { AliasId = 2, ExitId = 16, Alais = "Hall" };
            dbExit.ExitAliases.Add(exit);
            dbExit.ExitAliases.Add(exit2);
            aliasList = new List<ExitAlias> { exit, exit2 };
        }
        public void SetUp()
        {
            postageRepository = MockRepository.GenerateMock<IRepository<Postage>>();

            postageService = new PostageService(postageRepository);

            var postages = PostageTests.CreatePostages();
            postageRepository.Stub(pr => pr.GetAll()).Return(postages);
        }
        public void Context()
        {
            _emailRepository = MockRepository.GenerateMock<IRepository<Email>>();
            _emailTemplateRepository = MockRepository.GenerateStub<IRepository<EmailTemplate>>();
            const int emailTemplateId = 23;
            _emailTemplateRepository.Stub(a => a.GetById(emailTemplateId)).Return(new EmailTemplate(123));

            var handler = new CreateEmailCommandHandler(_emailRepository, _emailTemplateRepository);
            handler.CommandExecuted += (sender, args) => _eventRaised = true;
            handler.Execute(new CreateEmailCommand { EmailTemplateId = emailTemplateId});
        }
 public void SetUp()
 {
     builder = new PizzaTypeEditorConvention();
     pizzaType = new PizzaType { Id = new Guid(), Name = "Test", Description = "Test description" };
     order = new PickupOrder { Id = new Guid(), PizzaType = pizzaType };
     services = MockRepository.GenerateStub<IServiceLocator>();
     repository = MockRepository.GenerateStub<IRepository>();
     stringifier = new Stringifier();
     repository.Stub(r => r.GetAll<PizzaType>()).Return(new List<PizzaType> { pizzaType });
     services.Stub(l => l.GetInstance<IRepository>()).Return(repository);
     services.Stub(l => l.GetInstance<Stringifier>()).Return(stringifier);
 }
        protected override void Before_each()
        {
            _aiList = new List<AssaultItem>
                          {
                              new AssaultItem {Description = "Stormtrooper"},
                              new AssaultItem {Description = "AT-ST"}
                          };

            _repo = Stub<IRepository<AssaultItem>>();
            _repo.Stub(x => x.GetAll()).Return(_aiList);

            _service = new InventoryService(_repo);
        }
Esempio n. 7
0
 public void Initialize()
 {
     mockBookRepository = MockRepository.GenerateStub <IRepository <Book> >();
     mockBookRepository.Stub(s => s.GetData()).Return(new[]
     {
         new Book()
         {
             Name            = "TestBook",
             Authors         = "TestAuthorBook",
             PublishCity     = "TestCityBook",
             PublishingHouse = "TestPublishingHouseBook",
             PublishYear     = 2000,
             PageCount       = 0,
             Comment         = "TestCommentBook",
             ISBN            = "00000"
         }
     });
     mockNewspaperRepository = MockRepository.GenerateStub <IRepository <Newspaper> >();
     mockNewspaperRepository.Stub(s => s.GetData()).Return(new[]
     {
         new Newspaper()
         {
             Name            = "TestNameNewspaper",
             PublishCity     = "TestCityNewpaper",
             PublishingHouse = "TestPublishingHouseNewspaper",
             PublishYear     = 2000,
             PageCount       = 20,
             Comment         = "TestCommentNewspaper",
             SerialNumber    = 1,
             Date            = DateTime.Parse("2008-05-01 7:34:42Z"),
             ISSN            = "0734-7456"
         }
     });
     mockPatentRepository = MockRepository.GenerateStub <IRepository <Patent> >();
     mockPatentRepository.Stub(s => s.GetData()).Return(new[]
     {
         new Patent()
         {
             Name         = "TestNamePatent",
             Creator      = "TestCreaterPatent",
             Country      = "TestCountryPatent",
             SerialNumber = 1,
             RequestDate  = DateTime.Parse("2005-02-01 7:34:42Z"),
             PublishDate  = DateTime.Parse("2014-08-05 7:34:42Z"),
             PageCount    = 20,
             Comment      = "TestCommentPatent"
         }
     });
     manager = new XmlManager(mockBookRepository, mockNewspaperRepository, mockPatentRepository);
 }
        public void context()
        {
            MvcApplication.InitializeContainer(new TestContainer());

            var principal = MockRepository.GenerateStub<IPrincipal>();
            var visitor = MockRepository.GenerateStub<SiteVisitor>();
            visitor.Stub(x => x.FirstName).Return("Michael");

            userRepository = MockRepository.GenerateStub<IRepository<SiteVisitor>>();
            userRepository.Stub(x => x.Find(Arg<Func<SiteVisitor, bool>>.Is.Anything)).Return(new List<SiteVisitor>() { visitor });

            loginController = new LoginController(userRepository);
            loginController.Submit("*****@*****.**", System.Guid.NewGuid().ToString());
        }
Esempio n. 9
0
        public WebsiteRespositoryMockTests()
        {
            if (USE_MOCKED_SERVICE)
            {
                // Mocked Repository
                basicWebsiteRepo = MockRepository.GenerateMock <IRepository <Website> >();

                basicWebsiteRepo.Stub(e => e.Add(Arg <Website> .Is.Anything))
                .WhenCalled(x =>
                {
                    // Return what was passed in
                    x.ReturnValue = (Website)x.Arguments[0];
                });

                // Always return a Google Website when searching by ID
                basicWebsiteRepo.Stub(e =>
                                      e.GetById(Arg <Guid> .Is.Anything)).Return(new WebsiteBuilder().GoogleWebsite().Build());
            }
            else
            {
                basicWebsiteRepo = new BasicWebsiteRepository();
            }
        }
        public void ChangePatientNameCommand_should_change_Patient_Name()
        {
            Guid patientId = Guid.NewGuid();

            string originalName = "Jeff Carley";

            string expectedName = "Jefferson Carley";

            var patient = Patient.CreateNew(
                patientId,
                new PatientName(originalName),
                new PatientStatus("Active"),
                new Address("444 South Street", "Madison", "WI", "53701"));

            IRepository repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(r => r.GetById <Patient>(patientId, 0)).Return(patient);


            var commandHandler = new ChangePatientNameCommandHandler(repository);

            var command = new ChangePatientNameCommand(Guid.NewGuid(), patientId)
            {
                Name = expectedName
            };

            commandHandler.Handle(command);

            var args = repository.GetArgumentsForCallsMadeOn(r =>
                                                             r.Save(Arg <Patient> .Is.Anything, Arg <Guid> .Is.Anything, Arg <Action <IDictionary <string, object> > > .Is.Null));

            var actualPatient = args[0][0] as Patient;
            var list          = new ArrayList((actualPatient as IAggregate).GetUncommittedEvents());

            list.ShouldNotBeEmpty();

            PatientNameChangedEvent evt = null;

            foreach (var item in list)
            {
                if (item is PatientNameChangedEvent)
                {
                    evt = item as PatientNameChangedEvent;
                    break;
                }
            }

            evt.ShouldNotBeNull();
            evt.Name.ShouldEqual(expectedName);
        }
        public void Execute_Should_Set_the_Name_of_Ball_to_Orb()
        {
            // Arrange
            var ball = new Item() { ItemName = "Ball" };
            var ring = new Item() { ItemName = "Ring" };
            var list = new List<Item>() { ball, ring };
            repository.Stub(qq => qq.AsQueryable()).Return(list.AsQueryable());
            // Act
            cmd.Execute("item Ball.name = Orb");

            // Assert
            Assert.AreEqual("Orb", ball.ItemName);
            
            repository.AssertWasCalled(m => m.Dispose());
        }
Esempio n. 12
0
        public void Should_bind_correct_categories_to_product()
        {
            var category14 = new Category {
                Id = 14
            };
            var category15 = new Category {
                Id = 15
            };

            categoryRepository.Stub(r => r.GetById(14)).Return(category14);
            categoryRepository.Stub(r => r.GetById(15)).Return(category15);

            var product = new Product();

            context.SetProduct(product);
            context.ProductViewData.CategoryIds.Add(14);
            context.ProductViewData.CategoryIds.Add(15);

            contributor.ContributeTo(context);

            product.ProductCategories.Count.ShouldEqual(2);
            product.ProductCategories[0].Category.ShouldBeTheSameAs(category14);
            product.ProductCategories[1].Category.ShouldBeTheSameAs(category15);
        }
Esempio n. 13
0
        public void GlobalArrange()
        {
            repoFactory = MockRepository.GenerateMock<IRepositoryFactory>();
            factory = MockRepository.GenerateMock<IRepositoryFactoryFactory>();
            console = MockRepository.GenerateMock<IConsoleFacade>();
            repo = MockRepository.GenerateMock<IRepository>();
            uow = MockRepository.GenerateMock<IUnitOfWork>();
            goQueries = MockRepository.GenerateMock<IGameObjectQueries>();
            //formatters = MockRepository.GenerateMock<IFormatter[]>();

            factory.Stub(m => m.Create()).Return(repoFactory);
            repoFactory.Stub(m => m.Create()).Return(repo);
            repo.Stub(m => m.UnitOfWork).Return(uow);

            //target = new LookCommand(console, factory, goQueries, formatters);
        }
        public static IRepository <Game> CreateMockGameRepository()
        {
            IRepository <Game> mockedRepository = MockRepository.GenerateMock <IRepository <Game> >();

            mockedRepository.Expect(mr => mr.GetAll()).Return(CreateGames());
            mockedRepository.Expect(mr => mr.Get(1)).IgnoreArguments().Return(CreateGame());
            mockedRepository.Expect(mr => mr.SaveOrUpdate(null)).IgnoreArguments().Return(CreateGame());
            mockedRepository.Expect(mr => mr.Delete(null)).IgnoreArguments();

            IDbContext mockedDbContext = MockRepository.GenerateStub <IDbContext>();

            mockedDbContext.Stub(c => c.CommitChanges());
            mockedRepository.Stub(mr => mr.DbContext).Return(mockedDbContext);

            return(mockedRepository);
        }
Esempio n. 15
0
        public void BindTo_should_return_the_correct_select_list()
        {
            var ids = new[] {2, 3};
            var loopups = new System.Collections.Generic.List<ComboForLookup>()
            {
                new ComboForLookup {Id = 1, Name = "one"},
                new ComboForLookup {Id = 2, Name = "two"},
                new ComboForLookup {Id = 3, Name = "three"},
                new ComboForLookup {Id = 4, Name = "four"},
            };
            repository.Stub(x => x.GetAll()).Return(loopups.AsQueryable());

            var result = comboFor.Multiple().BoundTo("PropertyName", ids);
            //Console.Out.WriteLine("result = {0}", result);
            result.ShouldEqual(expectedSelectList);
        }
	    public void SetUp()
	    {
            basketRepository = MockRepository.GenerateStub<IRepository<Basket>>();
            encryptionService = MockRepository.GenerateStub<IEncryptionService>();
	        postageService = MockRepository.GenerateStub<IPostageService>();
	        userService = MockRepository.GenerateStub<IUserService>();

            checkoutService = new CheckoutService(basketRepository, encryptionService, postageService, userService);

            checkoutViewData = GetCheckoutViewData();
            basket = CreateBasketWithId(7);
            basketRepository.Stub(r => r.GetById(7)).Return(basket);

            user = new User { Role = Role.Administrator };
	        userService.Stub(u => u.CurrentUser).Return(user);
	    }
Esempio n. 17
0
        private IRepository <Team> CreateMockTeamRepository()
        {
            IRepository <Team> mockedRepository = MockRepository.GenerateMock <IRepository <Team> >();

            mockedRepository.Expect(mr => mr.GetAll()).Return(CreateTeams());
            mockedRepository.Expect(mr => mr.Get(1)).IgnoreArguments().Return(CreateTeam());
            mockedRepository.Expect(mr => mr.SaveOrUpdate(null)).IgnoreArguments().Return(CreateTeam());
            mockedRepository.Expect(mr => mr.Delete(null)).IgnoreArguments();

            IDbContext mockedDbContext = MockRepository.GenerateStub <IDbContext>();

            mockedDbContext.Stub(c => c.CommitChanges());
            mockedRepository.Stub(mr => mr.DbContext).Return(mockedDbContext);

            return(mockedRepository);
        }
        public void Execute_Should_List_Contents_Of_Inventory()
        {
            // Arrange
            repository.Stub(gg => gg.AsQueryable()).Return(new List <Item>
            {
                new Item {
                    RoomId = 2, ItemName = "sword"
                }
            }.AsQueryable());

            // Act
            cmd.Execute("inventory");

            // Assert
            mock.AssertWasCalled(m => m.Write("{0}  ", "sword"));
            repository.AssertWasCalled(m => m.Dispose());
        }
        public void SetUp()
        {
            _users = new List <User>();

            _repository  = MockRepository.GenerateStub <IRepository>();
            _userService = new UserService(_repository);

            _curUser = null;

            _repository.Stub(r => r.Query <User>(null)).IgnoreArguments().Return(_users.AsQueryable());

            GivenUserDisplayName = "username";
            GivenUserEmail       = "email";
            GivenUserUrl         = "www";

            _curUser = _userService.AddOrUpdateUser(GivenUserEmail, GivenUserDisplayName, GivenUserUrl);
        }
Esempio n. 20
0
        public void TestInitialize()
        {
            unitOfWork      = MockRepository.GenerateMock <IUnitOfWork>();
            currentUser     = MockRepository.GenerateMock <ICurrentUser>();
            topicRepository = MockRepository.GenerateMock <IRepository <TopicModel> >();
            List <TopicModel> topics = new List <TopicModel>();

            topics.Add(new TopicModel
            {
                Name          = "cats",
                Posts         = new List <PostModel>(),
                Subscriptions = new List <SubscriptionModel>()
            });
            topicRepository.Stub(rep => rep.Get()).Return(topics);
            unitOfWork.Stub(uow => uow.TopicRepository).Return(topicRepository);
            homeController = new HomeController(unitOfWork, currentUser);
        }
Esempio n. 21
0
        public void Authenticate_should_check_that_user_and_matching_password_exist_in_repository()
        {
            formsAuthentication.Stub(x => x.HashPasswordForStoringInConfigFile("foo")).Return("bar");

            var user = new User
            {
                Email     = "*****@*****.**",
                Password  = "******",
                IsEnabled = true
            };

            userRepository.Stub(r => r.GetAll()).Return(new[] { user }.AsQueryable());

            var isAuthenticated = userService.Authenticate("*****@*****.**", "foo");

            Assert.That(isAuthenticated, Is.True);
        }
Esempio n. 22
0
        public void SetUp()
        {
            basketRepository  = MockRepository.GenerateStub <IRepository <Basket> >();
            encryptionService = MockRepository.GenerateStub <IEncryptionService>();
            postageService    = MockRepository.GenerateStub <IPostageService>();
            userService       = MockRepository.GenerateStub <IUserService>();

            checkoutService = new CheckoutService(basketRepository, encryptionService, postageService, userService);

            checkoutViewData = GetCheckoutViewData();
            basket           = CreateBasketWithId(7);
            basketRepository.Stub(r => r.GetById(7)).Return(basket);

            user = new User {
                Role = Role.Administrator
            };
            userService.Stub(u => u.CurrentUser).Return(user);
        }
        public void BeforeAll()
        {
            var campsiteId = "the site number";
            _campsite = Builder<Campsite>.CreateNew().Do(c => c.Id = campsiteId).Build();

            _repository = MockRepository.GenerateStub<IRepository>();
            _repository.Stub(r => r.Get<Campsite>(campsiteId)).Return(_campsite);
           
            var command = new CreateCampsiteReviewCommand(_repository);

            _request = Builder<CreateCampsiteReviewRequest>
                .CreateNew()
                .Do(r=>r.CampsiteId = campsiteId)
                .Do(r=>r.Rating = 4)
                .Build();

            _response = command.Execute(_request);
        }
        public void BeforeAll()
        {
            _repository = MockRepository.GenerateStub<IRepository>();
            _repository.Stub(r => r.Find<Campground>()).Return(
                Builder<Campground>
                .CreateListOfSize(10)
                .Build()
                .AsQueryable());
            var command = new CreateCampgroundCommand(_repository);

            _request = Builder<CreateCampgroundRequest>
                .CreateNew()
                .Do(r=>r.Location = new []{45.5m,23.45m})
                .Do(r=>r.Name = "Where I camp at")
                .Build();

            _response = command.Execute(_request);
        }
Esempio n. 25
0
        public void Edit_ShouldDisplayCategoryEditViewWithCorrectCategory()
        {
            const int categoryId = 3;

            var category = new Category
            {
                Id     = categoryId,
                Name   = "My Category",
                Parent = new Category {
                    Id = 23
                }
            };

            categoryRepository.Stub(cr => cr.GetById(categoryId)).Return(category);

            var result = categoryController.Edit(categoryId);

            AssertEditViewIsCorrectlyShown(result);
        }
        public void MustReturnEmployeeForGetUsingAValidId()
        {
            // Arrange
            int id       = 12345;
            var employee = new Employee()
            {
                Id        = id,
                FirstName = "John",
                LastName  = "Human"
            };

            IRepository <Employee> repository = MockRepository.GenerateMock <IRepository <Employee> >();

            repository.Stub(x => x.Find(id)).Return(employee);

            IUnitOfWork uow = MockRepository.GenerateMock <IUnitOfWork>();

            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Employee, EmployeeDto>();
            });

            var controller = new EmployeesController(uow, repository, Mapper.Instance);

            controller.EnsureNotNull();

            // Act
            HttpResponseMessage response = controller.Get(id);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Content);
            Assert.IsInstanceOfType(response.Content, typeof(ObjectContent <EmployeeDto>));
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            var content = (response.Content as ObjectContent <EmployeeDto>);
            var result  = content.Value as EmployeeDto;

            Assert.AreEqual(employee.Id, result.Id);
            Assert.AreEqual(employee.FirstName, result.FirstName);
            Assert.AreEqual(employee.LastName, result.LastName);
        }
Esempio n. 27
0
        public void Edit_ShouldSelectCorrectUser()
        {
            const int userId = 23;

            var user = new User
            {
                Id       = userId,
                Email    = "*****@*****.**",
                Password = "******",
                Role     = new Role {
                    Id = 2
                }
            };

            userRepository.Stub(ur => ur.GetById(userId)).Return(user);

            var result = userController.Edit(userId) as ViewResult;

            AssertUserEditViewDataIsCorrect(result);
        }
Esempio n. 28
0
        public void Setup()
        {
            product = new Product
            {
                Reviews =
                {
                    new Review(),
                    new Review()
                }
            };

            productRepository = new FakeRepository <Product>(id =>
            {
                product.Id = id;
                return(product);
            });

            reviewRepository = MockRepositoryBuilder.CreateReviewRepository();

            commentRepository = MockRepository.GenerateStub <IRepository <IComment> >();

            var comments = new List <IComment>
            {
                new Comment {
                    Approved = true
                },
                new Comment {
                    Approved = false
                },
                new Review {
                    Approved = true
                },
                new Comment {
                    Approved = true
                }
            }.AsQueryable();

            commentRepository.Stub(r => r.GetAll()).Return(comments);

            controller = new ReviewsController(reviewRepository, productRepository, commentRepository);
        }
Esempio n. 29
0
        public void Should_create_new_mailing_list_subscription()
        {
            MailingListSubscription mailingListSubscription = null;

            mailingListRepository.Stub(r => r.SaveOrUpdate(null)).IgnoreArguments()
            .Do((Action <MailingListSubscription>)(m => mailingListSubscription = m));

            var order = new Order
            {
                ContactMe            = true,
                Email                = "*****@*****.**",
                UseCardHolderContact = true,
                CardContact          = new Contact()
            };

            handler.Handle(new OrderConfirmed(order));

            mailingListSubscription.Contact.ShouldBeTheSameAs(order.PostalContact);
            mailingListSubscription.Email.ShouldEqual("*****@*****.**");
            mailingListSubscription.DateSubscribed.Date.ShouldEqual(DateTime.Now.Date);
        }
        public void Index_should_return_postage_view()
        {
            const int basketId = 89;

            var basket = BasketTests.Create350GramBasket();

            basketRepository.Stub(b => b.GetById(basketId)).Return(basket);

            var postageResult = PostageResult.WithPrice(new Money(34.56M), "postage description");

            postageService.Stub(p => p.CalculatePostageFor(basket)).Return(postageResult);

            postageDetailController.Index(basketId)
            .ReturnsViewResult()
            .ForView("Index")
            .WithModel <PostageResultViewData>()
            .AssertAreEqual("�.56", vd => vd.PostageTotal)
            .AssertAreEqual("postage description", vd => vd.Description)
            .AssertAreEqual("�5.58", vd => vd.TotalWithPostage)
            .AssertAreSame(basket.Country, vd => vd.Country);
        }
        public void DogsControllerTestsSetup()
        {
            _dogsRepository = MockRepository.GenerateMock<IRepository<Dog>>();
              _breedsRepository = MockRepository.GenerateMock<IRepository<Breed>>();
              _placesRepository = MockRepository.GenerateMock<IPlacesRepository>();
              _unitofWork = MockRepository.GenerateMock<IUnitOfWork>();
              _dogSearchhelper = MockRepository.GenerateMock<IDogSearchService>();
              _configuration = MockRepository.GenerateMock<IConfiguration>();

              _breedsRepository.Stub(x => x.GetById(Arg<int>.Is.Anything)).Return(
            new Breed {Name = "Beagel"});

              _configuration.Stub(x => x.GetNationwideSearchResultsDescriptionMessageForAllBreeds())
            .Return("Search results {0} to {1} out of {2} results for all breeds nationwide.");
              _configuration.Stub(x => x.GetNationwideSearchResultsDescriptionMessageForSpecificBreed())
            .Return("Showing results {0} to {1} out of {2} results for {3} nationwide");
              _configuration.Stub(x => x.GetLocalSearchResultsDescriptionMessageForAllBreeds())
            .Return("Search results {0} to {1} out of {2} results for all breeds in {3}");

              _dogsController = new DogsController(_dogsRepository, _breedsRepository, _unitofWork, _dogSearchhelper, _configuration, _placesRepository);

              StubDogsRepository();
        }
Esempio n. 32
0
    public void TestMethod1()
    {
        _repository.Stub(x => x.GetAll()).Return(new List <Entity>().AsQueryable());

        //Test your target
    }
        public void SetUp()
        {
            _sessionPlayer = new Player();
            _databaseAccount = new Account {EmailAddress = "*****@*****.**"};
            _databasePlayer = new Player { Account = _databaseAccount };
            _sessionAccount = new Account();

            _httpSession = MockRepository.GenerateMock<IHttpSession>();
            _user = MockRepository.GenerateMock<IPrincipal>();
            _identity = MockRepository.GenerateMock<IIdentity>();
            _accountRepository = MockRepository.GenerateMock<IRepository<Account>>();
            _playerRepository = MockRepository.GenerateMock<IRepository<Player>>();

            _user.Stub(m => m.Identity).Return(_identity);
            _identity.Stub(m => m.Name).Return(_databaseAccount.EmailAddress);
            _accountRepository.Stub(m => m.Get).Return((new Collection<Account>{_databaseAccount}).AsQueryable());

            _userProvider = new TestUserProvider(_accountRepository, _playerRepository, _httpSession, _user);
        }
Esempio n. 34
0
        public void SetUp()
        {
            repository = MockRepository.GenerateMock<IRepository>();
            userTasks = MockRepository.GenerateMock<IUserTasks>();
            projectTaskType = new ProjectTaskType();
            user = new User();

            this.createWorkItemRequest = new CreateWorkItemRequest()
            {
                Name = "Bond",
                ProjectTaskTypeId = Guid.NewGuid()
            };
            repository.Stub(x => x.Get<ProjectTaskType>(createWorkItemRequest.ProjectTaskTypeId)).Return(projectTaskType);
            repository.Stub(x => x.Query<WorkItem>()).Return((new WorkItem[0]).AsQueryable());
            userTasks.Stub(x => x.GetCurrentUser()).Return(user);
        }
        public void RelocateCommand_should_change_Patient_Address()
        {
            Guid patientId = Guid.NewGuid();

            string originalStreet = "444 South Street";
            string orginalCity    = "Madison";
            string orginalState   = "WI";
            string orginalZip     = "53701";

            string expectedStreet = "123 Main St.";
            string expectedCity   = "Windsor";
            string expectedState  = "WI";
            string expectedZip    = "53598";

            var patient = Patient.CreateNew(
                patientId,
                new PatientName("Jeff Carley"),
                new PatientStatus("Active"),
                new Address(originalStreet, orginalCity, orginalState, orginalZip));

            IRepository repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(r => r.GetById <Patient>(patientId, 0)).Return(patient);


            var commandHandler = new RelocatePatientCommandHandler(repository);

            var command = new RelocatePatientCommand(Guid.NewGuid(), patientId)
            {
                Street = expectedStreet,
                City   = expectedCity,
                State  = expectedState,
                Zip    = expectedZip
            };

            commandHandler.Handle(command);

            var args = repository.GetArgumentsForCallsMadeOn(r =>
                                                             r.Save(Arg <Patient> .Is.Anything, Arg <Guid> .Is.Anything, Arg <Action <IDictionary <string, object> > > .Is.Null));

            var actualPatient = args[0][0] as Patient;
            var list          = new ArrayList((actualPatient as IAggregate).GetUncommittedEvents());

            list.ShouldNotBeEmpty();

            PatientRelocatedEvent evt = null;

            foreach (var item in list)
            {
                if (item is PatientRelocatedEvent)
                {
                    evt = item as PatientRelocatedEvent;
                    break;
                }
            }

            evt.ShouldNotBeNull();
            evt.Street.ShouldEqual(expectedStreet);
            evt.City.ShouldEqual(expectedCity);
            evt.State.ShouldEqual(expectedState);
            evt.Zip.ShouldEqual(expectedZip);
        }
        public void SetUp()
        {
            _users = new List<User>();

            _repository = MockRepository.GenerateStub<IRepository>();
            _userService = new UserService(_repository);

            _curUser = null;

            _repository.Stub(r => r.Query<User>(null)).IgnoreArguments().Return(_users.AsQueryable());

            GivenUserDisplayName = "username";
            GivenUserEmail = "email";
            GivenUserUrl = "www";
            GivenTwitterUserName = "******";

            _curUser = _userService.AddOrUpdateUser(GivenUserEmail, GivenUserDisplayName, GivenUserUrl, GivenTwitterUserName);
        }
        protected override void Before_each()
        {
            _repo = Stub<IRepository<AssaultItem>>();
            _repo.Stub(x => x.GetById(2)).Return(new AssaultItem {Description = "AI2"});

            _service = new InventoryService(_repo);
        }
        public void SetUp()
        {
            _posts = new List<Post>();
            _users = new List<User>();
            _repository = MockRepository.GenerateStub<IRepository>();
            _resolver = MockRepository.GenerateStub<IUrlResolver>();
            _blogPostCommentService = MockRepository.GenerateStub<IBlogPostCommentService>();
            _userService = MockRepository.GenerateStub<IUserService>();
            _controller = new BlogPostController(_repository, _resolver, _blogPostCommentService, _userService);

            _post = new Post { Slug = _testSlug };
            _posts.Add(_post);

            _repository
               .Stub(r => r.Query<Post>(null))
               .IgnoreArguments()
               .Return(_posts.AsQueryable());

            _repository
               .Stub(r => r.Query<User>(null))
               .IgnoreArguments()
               .Return(_users.AsQueryable());

            _testSlug = "TESTSLUG";

            _invalidInput = new BlogPostCommentViewModel {Slug = _testSlug};

            _validInput = new BlogPostCommentViewModel
            {
                DisplayName = "username",
                Email = "email",
                Body = "body",
                Subscribed = true,
                Slug = _testSlug
            };
        }
        protected override void Before_each()
        {
            _item = new AssaultItem {Description = "Description", Type = "Type", LoadValue = 2};

            _repo = Stub<IRepository<AssaultItem>>();
            _repo.Stub(x => x.Save(_item)).Return(9);
            _repo.Stub(x => x.GetById(9)).Return(_item);

            _service = new InventoryService(_repo);
        }
Esempio n. 40
0
        public void MultipleMocks_Test()
        {
            IRepository <MerchantEntity> merchantEntityMock = Mocker.CreateMock <IRepository <MerchantEntity> >();

            MerchantEntity merchantEntity = new MerchantEntity();

            merchantEntity.MerchantName = "Mocked Merchant";

            BasicRequest request = new BasicRequest();

            request.Id = 2;

            merchantEntityMock.Stub(p => p.GetById(request)).Return(merchantEntity);

            BasicRequest requestTest = new BasicRequest();

            requestTest.Id = 2;

            MerchantEntity merchantResult = merchantEntityMock.GetById(requestTest);

            Assert.IsNotNull(merchantResult);
            Assert.AreEqual("Mocked Merchant", merchantResult.MerchantName);

            IRepository <AcquirerEntity> acquirerEntityMock = Mocker.CreateMock <IRepository <AcquirerEntity> >();

            AcquirerEntity acquirerEntity = new AcquirerEntity();

            acquirerEntity.AcquirerName = "Mocked Acquirer";

            BasicRequest acquirerRequest = new BasicRequest();

            acquirerRequest.Id = 2;

            acquirerEntityMock.Stub(p => p.GetById(acquirerRequest)).Return(acquirerEntity);

            BasicRequest acquirerRequestTest = new BasicRequest();

            acquirerRequestTest.Id = 2;

            AcquirerEntity acquirerResult = acquirerEntityMock.GetById(acquirerRequestTest);

            Assert.IsNotNull(acquirerResult);
            Assert.AreEqual("Mocked Acquirer", acquirerResult.AcquirerName);

            AcquirerEntity anotherAquirerEntity = new AcquirerEntity();

            anotherAquirerEntity.AcquirerName = "Another Mocked Acquirer";

            BasicRequest acquirerRequest2 = new BasicRequest();

            acquirerRequest2.Id = 3;

            acquirerEntityMock.Stub(p => p.GetById(acquirerRequest2)).Return(anotherAquirerEntity);
            acquirerEntityMock.Stub(p => p.Name).Return("Banana");
            acquirerEntityMock.Stub(p => p.GetTypeName()).Return(new AcquirerEntity()
            {
                AcquirerName = "Mocked Acquirer Type"
            });

            BasicRequest anotherAcquirerRequestTest = new BasicRequest();

            anotherAcquirerRequestTest.Id = 3;

            AcquirerEntity anotherAcquirerResult = acquirerEntityMock.GetById(anotherAcquirerRequestTest);

            Assert.IsNotNull(anotherAcquirerResult);
            Assert.AreEqual("Another Mocked Acquirer", anotherAcquirerResult.AcquirerName);

            string nameResult = acquirerEntityMock.Name;

            Assert.IsNotNull(nameResult);
            Assert.AreEqual("Banana", nameResult);

            AcquirerEntity mockAcquirerType = acquirerEntityMock.GetTypeName();

            Assert.IsNotNull(mockAcquirerType);
            Assert.AreEqual("Mocked Acquirer Type", mockAcquirerType.AcquirerName);
        }
Esempio n. 41
0
        public void StartUp()
        {
            if (App == null)
            {
                Thread newWindowThread = new Thread((input) =>
                {
                    SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));

                    App = new App();
                    App.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    var foo          = new Uri("pack://application:,,,/DefaultViews;component/Resources/CommonStyles.xaml", UriKind.Absolute);
                    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
                    {
                        Source = foo
                    });
                    var foo2 = new Uri("pack://application:,,,/DefaultViews;component/Resources/DataTemplates.xaml", UriKind.Absolute);
                    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
                    {
                        Source = foo2
                    });
                    var foo3 = new Uri("pack://application:,,,/DefaultViews;component/Resources/LiveDataTemplates.xaml", UriKind.Absolute);
                    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
                    {
                        Source = foo3
                    });

                    App.Run();
                });

                newWindowThread.SetApartmentState(ApartmentState.STA);
                newWindowThread.IsBackground = true;

                newWindowThread.Start();
                do
                {
                    Thread.Sleep(10);
                    Dispatcher = Dispatcher.FromThread(newWindowThread);
                } while (Dispatcher == null);
            }
            var dispatcher = new MyDispatcher(Dispatcher);

            IoCContainer.Kernel = new StandardKernel();
            IoCContainer.Kernel.Bind <IWaitOverlayProvider>().To <WaitOverlayProvider>().InSingletonScope();
            IoCContainer.Kernel.Bind <ITicketHandler>().To <TicketHandler>().InSingletonScope();

            ChangeTracker = new ChangeTracker();
            IoCContainer.Kernel.Bind <IChangeTracker>().ToConstant <IChangeTracker>(ChangeTracker).InSingletonScope();
            IoCContainer.Kernel.Bind <IStationRepository>().To <StationRepository>().InSingletonScope();


            MessageMediator     = new MyMessageMediator();
            MyRegionManager     = new MyRegionManager();
            TranslationProvider = MockRepository.GenerateStub <ITranslationProvider>();
            LineSr                 = MockRepository.GenerateStub <ILineSr>();
            Repository             = MockRepository.GenerateStub <IRepository>();
            WsdlRepository         = MockRepository.GenerateStub <IWsdlRepository>();
            ConfidenceFactor       = MockRepository.GenerateStub <IConfidenceFactor>();
            TransactionQueueHelper = MockRepository.GenerateStub <ITransactionQueueHelper>();

            IoCContainer.Kernel.Bind <IMediator>().ToConstant <IMediator>(MessageMediator).InSingletonScope();
            IoCContainer.Kernel.Bind <IMyRegionManager>().ToConstant <IMyRegionManager>(MyRegionManager).InSingletonScope();
            IoCContainer.Kernel.Bind <IDispatcher>().ToConstant <IDispatcher>(dispatcher).InSingletonScope();
            IoCContainer.Kernel.Bind <IRepository>().ToConstant <IRepository>(Repository).InSingletonScope();
            IoCContainer.Kernel.Bind <ILineSr>().ToConstant <ILineSr>(LineSr).InSingletonScope();
            IoCContainer.Kernel.Bind <ITranslationProvider>().ToConstant <ITranslationProvider>(TranslationProvider).InSingletonScope();
            IoCContainer.Kernel.Bind <IWsdlRepository>().ToConstant <IWsdlRepository>(WsdlRepository).InSingletonScope();
            IoCContainer.Kernel.Bind <IConfidenceFactor>().ToConstant <IConfidenceFactor>(ConfidenceFactor).InSingletonScope();
            IoCContainer.Kernel.Bind <ITransactionQueueHelper>().ToConstant <ITransactionQueueHelper>(TransactionQueueHelper).InSingletonScope();

            long lastTicketNumber  = 0;
            long lastTransactionId = 0;

            WsdlRepository.Stub(x => x.GetBusinessProps(null, out lastTicketNumber, out lastTransactionId)).Return(1).IgnoreArguments();
            Repository.Stub(x => x.FindMatches(null, null, null, null, null)).Return(new SortableObservableCollection <IMatchVw>()).IgnoreArguments();
            TransactionQueueHelper.Stub(x => x.GetCountTransactionQueue()).Return(1).IgnoreArguments();

            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_RESULTS_MINUS_X_DAYS)).Return("{0}");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_MANIPULATION_FEE)).Return("ManipulationFee");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_BONUS)).Return("bonus");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_MINBET)).Return("min bet");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_MAXBET)).Return("max bet");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_MAXWIN)).Return("Max Win");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_AVAILABLE_CASH)).Return("Available cash");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_ODD)).Return("Odd:");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_PRINT_STAKE_TOTAL)).Return("Total Stake");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.CLOSE)).Return("Close");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.OUTRIGHTS)).Return("Outrights");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_PLEASE_ADD_AMOUNT)).Return("{0}");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.HELLO_MSG)).Return("hello {0}");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_CHANGE_PASSWORD)).Return("change password");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_FORM_ALL)).Return("all");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_TICKETWON)).Return("all");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_TICKETWON)).Return("won");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_TICKETLOST)).Return("lost");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_FORM_CANCELLED)).Return("canceled");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_TICKETOPEN)).Return("open");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.SHOW_SELECTED)).Return("show selected");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_NAVIGATION_FORWARD)).Return("forward");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.SHOP_FORM_NO_CONNECTION_TO_SERVER)).Return("no conenction");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TRANSFER_TO_ACCOUNT)).Return("to account");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_FORM_STATION_LOCKED_BY_ADMIN)).Return("locked by admin");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_CASH_LOCKED)).Return("locked cash");
            TranslationProvider.Stub(x => x.Translate(MultistringTags.TERMINAL_FORM_REQUIRED)).Return("required");
        }
        public void Setup()
        {
            _category1 = new Category {CategoryID = 1};
            _category2 = new Category {CategoryID = 2};
            _post1 = new Post { PostID = 1, PostedAt = DateTime.Now.Subtract(TimeSpan.FromDays(50)), Categories = new Collection<Category>{_category1}};
            _post2 = new Post { PostID = 2,  PostedAt = DateTime.Now, Categories = new Collection<Category>{ _category2}};
            List<Post> posts = new List<Post> { _post1, _post2 };

            _unitOfWorkFactory = MockRepository.GenerateStub<IUnitOfWorkFactory>();
            _unitOfWork = MockRepository.GenerateStub<IUnitOfWork>();
            _postRepository = MockRepository.GenerateStub<IRepository<Post>>();
            _mapper = MockRepository.GenerateStub<IMapper<Post, PostViewModel>>();

            _unitOfWorkFactory.Stub(x => x.Create()).Return(_unitOfWork);
            _unitOfWork.Stub(x => x.GetRepository<Post>()).Return(_postRepository);
            _unitOfWork.Stub(x => x.Execute(Arg<Action>.Is.Anything)).WhenCalled(x => ((Action)x.Arguments[0])());

            _postRepository.Stub(y => y.AllIncluding(Arg<Expression<Func<Post, object>>>.Is.Anything)).Return(posts.AsQueryable());
        }