public void makeTransfer_NotEnoughMoneyDebitAccountButOverdraftAllowed()
        {
            //arrange
            IOperationRepository operationRepository = MockRepository.GenerateStub <IOperationRepository>();
            IRepository          repository          = MockRepository.GenerateMock <IRepository>();
            IDtoCreator <Operation, OperationDto> operationCreator = MockRepository.GenerateStub <IDtoCreator <Operation, OperationDto> >();

            Account debitAccount = new Account()
            {
                Id = 1, Balance = 0, AuthorizeOverdraft = true
            };
            Account creditAccount = new Account()
            {
                Id = 2, Balance = 300
            };

            repository.Expect(x => x.Get <Account>(debitAccount.Id)).Return(debitAccount);
            repository.Expect(x => x.Get <Account>(creditAccount.Id)).Return(creditAccount);

            //act
            OperationServices services = new OperationServices(operationRepository, repository, operationCreator);

            services.MakeTransfer(debitAccount.Id, creditAccount.Id, 200, "");

            //assert
            Assert.AreEqual(-200, debitAccount.Balance);
            repository.VerifyAllExpectations();
        }
Esempio n. 2
0
        public void Records(int count, IRepository <T> repository, List <T> specificRecords)
        {
            var records = new List <T>();
            var specificRecordsCount = 0;

            if (specificRecords != null)
            {
                specificRecordsCount = specificRecords.Count;
                for (int i = 0; i < specificRecordsCount; i++)
                {
                    records.Add(specificRecords[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                records.Add(CreateValid(i + specificRecordsCount + 1));
            }

            var totalCount = records.Count;

            for (int i = 0; i < totalCount; i++)
            {
                records[i].SetIdTo(i + 1);
                int i1 = i;
                repository
                .Expect(a => a.GetNullableById(i1 + 1))
                .Return(records[i])
                .Repeat
                .Any();
            }
            repository.Expect(a => a.GetNullableById(totalCount + 1)).Return(null).Repeat.Any();
            repository.Expect(a => a.Queryable).Return(records.AsQueryable()).Repeat.Any();
            repository.Expect(a => a.GetAll()).Return(records).Repeat.Any();
        }
        public async Task WillCallTestLoginMethodOnIsUserLoggedInAsync()
        {
            var logic = new LoginLogic(_oAuthManager, null, null, _tokenRepository, _userRepository, _preferencesRepository,
                                       _updateRepository, _donateIntentRepo);

            const string tokenString = "Some String";

            _tokenRepository.Expect(t => t.Get()).Return(new Token
            {
                TokenString = tokenString,
                Secret      = null
            });
            _userRepository.Expect(t => t.Get()).Return(new User());

            _oAuthManager.Expect(o => o.MakeAuthenticatedRequestAsync(Arg <string> .Is.Anything, Arg <IDictionary <string, string> > .Is.Anything))
            .Return(Task.FromResult <dynamic>((dynamic) new Dictionary <string, object>()));

            var applyUser = new Action <User>(delegate { });

            await logic.IsUserLoggedInAsync(applyUser);

            _tokenRepository.VerifyAllExpectations();
            _userRepository.VerifyAllExpectations();
            _oAuthManager.VerifyAllExpectations();
        }
        public void Should_return_a_bad_redirect_result_if_nothing_is_returned_from_Repository()
        {
            var testSlug = "My-Test-Slug";
            var postList = new List <Post> {
                new Post {
                    ID = Guid.NewGuid(), Title = "My Title"
                }
            }.AsQueryable();

            // Problem is with this somewhere
            //_repository.Stub(call => call.Query(new PostBySlug(testSlug))).IgnoreArguments().Return(postList);
            _repository.Expect(call => call.Query(new PostBySlug(testSlug))).IgnoreArguments().Return(postList);
            _repository.Expect(call => call.Query(new PostBySlug(testSlug)).SingleOrDefault()).IgnoreArguments().Return(null);

            var outModel = _controller.Edit(new BlogPostEditViewModel {
                Slug = testSlug
            });

            outModel.ShouldBeOfType <BlogPostAddViewModel>();

            var actualResult = outModel as BlogPostAddViewModel;

            actualResult.ShouldNotBeNull();
            actualResult.ResultOverride.ShouldBeOfType <RedirectResult>();
        }
Esempio n. 5
0
        public void MailingListSubscriptions_ShouldReturnASscFileOfSubscriptions()
        {
            var subscriptions = new[]
            {
                new MailingListSubscription
                {
                    Contact = new Contact()
                    {
                        Firstname = "Firstname",
                        Lastname  = "Lastname",
                        Address1  = "Address1",
                        Address2  = "Address2",
                        Address3  = "Address3",
                        Town      = "Town",
                        County    = "County",
                        Postcode  = "Postcode",
                        Telephone = "01234567891",
                        Country   = new Country()
                        {
                            Name = "UK"
                        },
                    },
                    Email = "*****@*****.**"
                },
                new MailingListSubscription
                {
                    Contact = new Contact
                    {
                        Firstname = "Firstname2",
                        Lastname  = "Lastname2",
                        Address1  = "Address12",
                        Address2  = "Address22",
                        Address3  = "Address32",
                        Town      = "Town2",
                        County    = "County2",
                        Postcode  = "Postcode2",
                        Telephone = "01234567892",
                        Country   = new Country()
                        {
                            Name = "UK"
                        },
                    },
                    Email = "*****@*****.**"
                }
            }.AsQueryable();

            mailingListRepository.Expect(x => x.GetAll()).Return(subscriptions);

            var result = reportController
                         .MailingListSubscriptions()
                         .ReturnsContentResult()
                         .Content.Split(new[] { ',', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

            var expected = expectedSubscriptionsCsv.Split(new[] { ',', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < 22; i++)
            {
                result[i].ShouldEqual(expected[i]);
            }
        }
        public void List_DisplaysAllSubscriptions()
        {
            var subscriptions = new[]
            {
                new MailingListSubscription
                {
                    Email = "*****@*****.**", DateSubscribed = new DateTime(2008, 1, 1), Contact = new Contact()
                    {
                        Country = new Country(),
                    }
                },
                new MailingListSubscription
                {
                    Email = "*****@*****.**", DateSubscribed = new DateTime(2009, 1, 2), Contact = new Contact()
                    {
                        Country = new Country()
                    }
                },
                new MailingListSubscription
                {
                    Email = "*****@*****.**", DateSubscribed = new DateTime(2007, 1, 1), Contact = new Contact()
                    {
                        Country = new Country()
                    }
                }
            };

            mailingListRepository.Expect(x => x.GetAll()).Return(subscriptions.AsQueryable());

            var model = controller.List(null)
                        .ReturnsViewResult()
                        .WithModel <ShopViewData>();

            model.MailingListSubscriptions.Count().ShouldEqual(3);
        }
        /// <summary>
        /// Fakes the ceremony.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="ceremonyRepository">The ceremony repository.</param>
        /// <param name="specificCeremonies">The specific ceremonies.</param>
        public static void FakeCeremony(int count, IRepository<Ceremony> ceremonyRepository, List<Ceremony> specificCeremonies)
        {
            var ceremonies = new List<Ceremony>();
            var specificTransactionsCount = 0;
            if (specificCeremonies != null)
            {
                specificTransactionsCount = specificCeremonies.Count;
                for (int i = 0; i < specificTransactionsCount; i++)
                {
                    ceremonies.Add(specificCeremonies[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                ceremonies.Add(CreateValidEntities.Ceremony(i + specificTransactionsCount + 1));
            }

            var totalCount = ceremonies.Count;
            for (int i = 0; i < totalCount; i++)
            {
                ceremonies[i].SetIdTo(i + 1);
                int i1 = i;
                ceremonyRepository
                    .Expect(a => a.GetNullableById(i1 + 1))
                    .Return(ceremonies[i])
                    .Repeat
                    .Any();
            }
            ceremonyRepository.Expect(a => a.GetNullableById(totalCount + 1)).Return(null).Repeat.Any();
            ceremonyRepository.Expect(a => a.Queryable).Return(ceremonies.AsQueryable()).Repeat.Any();
            ceremonyRepository.Expect(a => a.GetAll()).Return(ceremonies).Repeat.Any();
        }
Esempio n. 8
0
        public void CreateAccount_ok()
        {
            //arrange
            IRepository         repository                   = MockRepository.GenerateStub <IRepository>();
            IAccountRepository  accountRepository            = MockRepository.GenerateStub <IAccountRepository>();
            ICustomerRepository thirdPartyRepository         = MockRepository.GenerateStub <ICustomerRepository>();
            IDtoCreator <Account, AccountDto> accountCreator = new AccountDtoCreator();

            string   accountName = "name";
            Customer customer    = new Customer()
            {
                Id = 1
            };
            Role role = new Role {
                Id = 1
            };

            repository.Expect(x => x.Get <Customer>(customer.Id)).Return(customer);
            repository.Expect(x => x.Get <Role>(role.Id)).Return(role);

            //act
            IAccountServices services = new AccountServices(repository, accountRepository, thirdPartyRepository, accountCreator);

            services.CreateAccount(accountName, customer.Id, role.Id);

            //assert
            repository.VerifyAllExpectations();
            repository.AssertWasCalled(x => x.SaveOrUpdate <Customer>(customer));
            repository.AssertWasCalled(x => x.Save <Account>(Arg <Account> .Is.NotNull));
        }
            public void ShouldPersistANewUser()
            {
                _userRepositoryMock.Expect(x => x.Add(new User())).IgnoreArguments().Repeat.Once();
                _userRepositoryMock.Expect(x => x.Persist()).Repeat.Once();

                _userRegistrationApplicationService.PersistNewUser(new User());

                _userRepositoryMock.VerifyAllExpectations();
            }
        public void InvokingCalculateLoan_InvokesCompoundInterestOnStrategy()
        {
            _compoundStrategy.Expect(x => x.CompoundInterest(Arg <decimal> .Is.Anything, Arg <double> .Is.Anything)).Return(100);
            _repository.Expect(x => x.RetrieveAvailableLenders()).Return(LenderList);
            _loanMatcher.Expect(x => x.Match(Arg <decimal> .Is.Anything, Arg <List <Lender> > .Is.Anything)).Return(MatchedLenderList);

            _calculator.CalculateLoan(640, 36);
            _compoundStrategy.VerifyAllExpectations();
        }
        private IRepository <Category> CreateMockCategoryRepository()
        {
            IRepository <Category> repository = MockRepository.GenerateMock <IRepository <Category> >( );

            repository.Expect(r => r.GetAll()).Return(CreateCategories());
            repository.Expect(r => r.Get(1)).IgnoreArguments().Return(CreateCategory());
            repository.Expect(r => r.SaveOrUpdate(null)).IgnoreArguments().Return(CreateCategory());

            return(repository);
        }
Esempio n. 12
0
        public void Edit_should_render_view()
        {
            var menu = new Menu();

            menuRepository.Expect(x => x.GetAll()).Return(new List <Menu>().AsQueryable());
            menuRepository.Expect(x => x.GetById(3)).Return(menu);
            controller.Edit(3)
            .WithModel <CmsViewData>()
            .AssertAreSame(menu, x => x.Content);
        }
        public void Index_RendersViewWithCountries()
        {
            var countries = new List <Country>().AsQueryable();

            countryRepository.Expect(x => x.GetAll()).Return(countries);

            controller.Index()
            .ReturnsViewResult()
            .WithModel <ShopViewData>()
            .AssertAreSame(countries, x => x.Countries);
        }
Esempio n. 14
0
        public void MoveUpShouldMoveElementUp()
        {
            var things = MoveTests.MakeSomeThings().AsQueryable();

            thingRepository.Expect(tr => tr.GetAll()).Return(things);

            // move two up to top
            orderService.MoveItemAtPosition(2).UpOne();

            Assert.AreEqual("two", things.Single(t => t.Position == 1).Name);
        }
        public void BlogUpdateTest()
        {
            var blog = new Blog()
            {
                BlogId = 1, Url = "http://www.google.com"
            };

            _blogRepository.Expect(m => m.Update(Arg <Blog> .Is.NotNull, Arg <bool> .Is.Anything)).Repeat.Once();
            _blogService.SaveBlog(blog, true);
            _blogRepository.AssertWasCalled(m => m.Update(Arg <Blog> .Is.NotNull, Arg <bool> .Is.Anything), m => m.Repeat.Once());
        }
Esempio n. 16
0
        public void Index_ShouldShowListOfPostages()
        {
            var postages = new List <Postage>();

            postageRepository.Expect(pr => pr.GetAll()).Return(postages.AsQueryable());

            postageController.Index(1)
            .ReturnsViewResult()
            .ForView("Index")
            .WithModel <ScaffoldViewData <Postage> >()
            .AssertNotNull(vd => vd.Items);
        }
Esempio n. 17
0
        public void Index_ShouldPassRootCategoryToIndexView()
        {
            var root = BuildCategories();

            categoryRepository.Expect(cr => cr.GetById(1)).Return(root);

            stockController.Index()
            .ReturnsViewResult()
            .ForView("Index")
            .WithModel <ShopViewData>()
            .AssertAreSame(root, vd => vd.Category);
        }
 public void Setup()
 {
     _validEmployee1 = ObjectMother.ValidEmployee("emp1").WithEntityId(1);
     _validEmployee2 = ObjectMother.ValidEmployee("emp2").WithEntityId(2);
     _selectedEmployees = new[] { _validEmployee2, _validEmployee2 };
     _selectedEntities = new[]{_validEmployee1,_validEmployee2};
     dto = new SelectBoxPickerDto{Selected = new[]{"1","2"}};
     _repo = MockRepository.GenerateMock<IRepository>();
     _repo.Expect(x => x.Find<Employee>(1)).Return(_validEmployee1);
     _repo.Expect(x => x.Find<Employee>(2)).Return(_validEmployee2);
     _selectBoxPickerService = new SelectBoxPickerService(_selectListItemService,_repo);
     _result = _selectBoxPickerService.GetListOfSelectedEntities<Employee>(dto);
 }
 public void Setup()
 {
     _validEmployee1    = ObjectMother.ValidEmployee("emp1").WithEntityId(1);
     _validEmployee2    = ObjectMother.ValidEmployee("emp2").WithEntityId(2);
     _selectedEmployees = new[] { _validEmployee2, _validEmployee2 };
     _selectedEntities  = new[] { _validEmployee1, _validEmployee2 };
     dto = new SelectBoxPickerDto {
         Selected = new[] { "1", "2" }
     };
     _repo = MockRepository.GenerateMock <IRepository>();
     _repo.Expect(x => x.Find <Employee>(1)).Return(_validEmployee1);
     _repo.Expect(x => x.Find <Employee>(2)).Return(_validEmployee2);
     _selectBoxPickerService = new SelectBoxPickerService(_selectListItemService, _repo);
     _result = _selectBoxPickerService.GetListOfSelectedEntities <Employee>(dto);
 }
Esempio n. 20
0
            public void Should_create_one_dto_for_each_of_the_worksheet()
            {
                AddProperties();

                _excelRepository.Expect(x => x.GetWorkSheetNames()).IgnoreArguments().Return(_workSheetNames);
                _excelRepository.Expect(x => x.GetDTOClassAttributes("")).IgnoreArguments().Return(_classAttributes1);
                _excelRepository.Expect(x => x.GetDTOClassAttributes("")).IgnoreArguments().Return(_classAttributes2);
                _classGenerator.Expect(x => x.Create(null)).IgnoreArguments();
                _assemblyGenerator.Expect(x => x.Compile(null, null)).IgnoreArguments().Return(true);

                Assert.IsTrue(_excelToDtoMapper.Run(TestData.AssemblyName, _excelFiles));
            }
        public void Index_Test()
        {
            // Arrange
            var returnItems = new List <Foo>()
            {
                new Foo()
                {
                    Id = 1
                }, new Foo()
                {
                    Id = 2
                }
            };

            modelRepo.Expect(action => action.All).Return(returnItems.AsQueryable());

            // Act
            var result = controller.Index();

            // Assert
            Assert.That(result.Model, Is.InstanceOf <IEnumerable <Foo> >(), "TypeOf Model");
            var typedModel = (IEnumerable <Foo>)result.Model;

            Assert.That(typedModel.Count(), Is.EqualTo(2), "Model Items");
        }
Esempio n. 22
0
        public new void SetUp()
        {
            _activityType1 = new ActivityLogType
            {
                Id            = 1,
                SystemKeyword = "TestKeyword1",
                Enabled       = true,
                Name          = "Test name1"
            };
            _activityType2 = new ActivityLogType
            {
                Id            = 2,
                SystemKeyword = "TestKeyword2",
                Enabled       = true,
                Name          = "Test name2"
            };
            _customer1 = new Customer()
            {
                Id       = 1,
                Email    = "*****@*****.**",
                Username = "******",
                Deleted  = false,
            };
            _customer2 = new Customer()
            {
                Id       = 2,
                Email    = "*****@*****.**",
                Username = "******",
                Deleted  = false,
            };
            _activity1 = new ActivityLog()
            {
                Id = 1,
                ActivityLogType = _activityType1,
                CustomerId      = _customer1.Id,
                Customer        = _customer1
            };
            _activity2 = new ActivityLog()
            {
                Id = 2,
                ActivityLogType = _activityType1,
                CustomerId      = _customer2.Id,
                Customer        = _customer2
            };

            _workContext               = MockRepository.GenerateMock <IWorkContext>();
            _activityLogRepository     = MockRepository.GenerateMock <IRepository <ActivityLog> >();
            _activityLogTypeRepository = MockRepository.GenerateMock <IRepository <ActivityLogType> >();
            _customerRepository        = MockRepository.GenerateMock <IRepository <Customer> >();
            _activityLogTypeRepository.Expect(x => x.Table).Return(new List <ActivityLogType>()
            {
                _activityType1, _activityType2
            }.AsQueryable());
            _activityLogRepository.Expect(x => x.Table).Return(new List <ActivityLog>()
            {
                _activity1, _activity2
            }.AsQueryable());

            _customerActivityService = new CustomerActivityService(_activityLogRepository, _activityLogTypeRepository, _customerRepository, _workContext, null);
        }
Esempio n. 23
0
        public void TestGetCustomersForAdvisor()
        {
            //arrange
            IRepository         repository                  = MockRepository.GenerateStub <IRepository>();
            ICustomerRepository customerRepository          = MockRepository.GenerateStub <ICustomerRepository>();
            IAccountServices    accountServices             = MockRepository.GenerateStub <IAccountServices>();
            IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            Advisor advisor1 = new Advisor {
                Id = 1, FirstName = "Ad1"
            };
            Advisor advisor2 = new Advisor {
                Id = 2, FirstName = "Ad2"
            };
            List <Customer> customers = new List <Customer>();

            customers.Add(new Customer {
                Advisor = advisor1, Id = 1
            });
            customers.Add(new Customer {
                Advisor = advisor2, Id = 2
            });
            advisor1.Customers = customers;
            //repository.Expect(x=>x.GetAll<Customer>()).Return(customers);
            repository.Expect(x => x.Get <Advisor>(advisor1.Id)).Return(advisor1);

            //act
            CustomerServices   services = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            List <CustomerDto> recieved = (List <CustomerDto>)services.GetCustomersForAdvisor(advisor1.Id);

            //assert
            Assert.AreEqual(recieved[0].Id, 1);
            repository.VerifyAllExpectations();
        }
		public void Setup()
		{
			products= new List<Product>();
			images = new List<Image>();
			validator = MockRepository.GenerateStub<IValidatingBinder>();
			repository = MockRepository.GenerateStub<IRepository<Product>>();
			repository.Expect(x => x.GetAll()).Return(products.AsQueryable());
			fileService = MockRepository.GenerateStub<IHttpFileService>();
			imageOrderableService = MockRepository.GenerateStub<IOrderableService<ProductImage>>();
			fileService.Expect(x => x.GetUploadedImages(null)).IgnoreArguments().Return(images);
			sizeService = MockRepository.GenerateStub<ISizeService>();
			
			var resolver = MockRepository.GenerateStub<IRepositoryResolver>();
			
			controllerContext = new ControllerContext()
			{
				HttpContext = MockRepository.GenerateStub<HttpContextBase>()
			};

			controllerContext.HttpContext.Stub(x => x.Request).Return(MockRepository.GenerateStub<HttpRequestBase>());
			sizeService.Expect(x => x.WithValues(controllerContext.HttpContext.Request.Form)).Return(sizeService);

			valueProvider = new FakeValueProvider();
			bindingContext = new ModelBindingContext() 
			{
				ModelState = new ModelStateDictionary(),
                ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(Product)),
				ModelName = "product",
				ValueProvider = valueProvider
			};

			binder = new ProductBinder(validator, resolver, repository, fileService, imageOrderableService, sizeService);
		}
Esempio n. 25
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);
        }
Esempio n. 26
0
        public void Update_ShouldUpdateStockItems()
        {
            var form = new FormCollection
            {
                { "stockitem_0", "false" },
                { "stockitem_1", "true,false" },
                { "stockitem_2", "false" }
            };

            var sizes = CreateSizes();

            sizeRepository.Expect(s => s.GetAll()).Return(sizes);

            var root = BuildCategories();

            categoryRepository.Expect(cr => cr.GetById(1)).Return(root);

            stockController.Index(form)
            .ReturnsViewResult()
            .ForView("Index")
            .WithModel <ShopViewData>()
            .AssertNotNull(vd => vd.Category);

            Assert.That(sizes.First().IsInStock, Is.True);
            Assert.That(sizes.Last().IsInStock, Is.False);
        }
Esempio n. 27
0
        public new void SetUp()
        {
            _languageRepo = MockRepository.GenerateMock <IRepository <Language> >();
            var lang1 = new Language
            {
                Name              = "English",
                LanguageCulture   = "en-Us",
                FlagImageFileName = "us.png",
                Published         = true,
                DisplayOrder      = 1
            };
            var lang2 = new Language
            {
                Name              = "Russian",
                LanguageCulture   = "ru-Ru",
                FlagImageFileName = "ru.png",
                Published         = true,
                DisplayOrder      = 2
            };

            _languageRepo.Expect(x => x.Table).Return(new List <Language>()
            {
                lang1, lang2
            }.AsQueryable());

            var cacheManager = new NopNullCache();

            _settingService = MockRepository.GenerateMock <ISettingService>();

            _eventPublisher = MockRepository.GenerateMock <IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg <object> .Is.Anything));

            _localizationSettings = new LocalizationSettings();
            _languageService      = new LanguageService(cacheManager, _languageRepo, _settingService, _localizationSettings, _eventPublisher);
        }
        public new void SetUp()
        {
            _languageRepo = MockRepository.GenerateMock<IRepository<Language>>();
            var lang1 = new Language
            {
                Name = "English",
                LanguageCulture = "en-Us",
                FlagImageFileName = "us.png",
                Published = true,
                DisplayOrder = 1
            };
            var lang2 = new Language
            {
                Name = "Russian",
                LanguageCulture = "ru-Ru",
                FlagImageFileName = "ru.png",
                Published = true,
                DisplayOrder = 2
            };

            _languageRepo.Expect(x => x.Table).Return(new List<Language>() { lang1, lang2 }.AsQueryable());

            _storeMappingRepo = MockRepository.GenerateMock<IRepository<StoreMapping>>();

            var cacheManager = new NopNullCache();

            _settingService = MockRepository.GenerateMock<ISettingService>();

            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));

            _localizationSettings = new LocalizationSettings();
            _languageService = new LanguageService(cacheManager, _languageRepo, _storeMappingRepo,
                _settingService, _localizationSettings, _eventPublisher);
        }
        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);
        }
        public void Setup()
        {
            var entity1 = new SolutionFeatureConfig
            {
                Id = 1,
                IsForBPSubmission = true
            };

            var entity2 = new SolutionFeatureConfig
            {
                Id = 2,
                IsForBPSubmission = true
            };

            var entity3 = new SolutionFeatureConfig
            {
                Id = 3,
                IsForBPSubmission = false
            };

            var entity4 = new SolutionFeatureConfig
            {
                Id = 4
            };

            var cacheManager = new NopNullCache();
            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));

            _solutionFeatureConfigRepo = MockRepository.GenerateMock<IRepository<SolutionFeatureConfig>>();
            _solutionFeatureConfigRepo.Expect(x => x.Table).Return(new List<SolutionFeatureConfig> { entity1, entity2, entity3, entity4 }.AsQueryable());

            _solutionFeatureConfigService = new SolutionFeatureConfigService(cacheManager, _solutionFeatureConfigRepo, _eventPublisher);
        }
Esempio n. 31
0
        public void MustReturn201AndLinkForPost()
        {
            // Arrange
            int id          = 12345;
            var employeeDto = new EmployeeDto()
            {
                Id = id, FirstName = "John", LastName = "Human"
            };
            string requestUri        = "http://localhost:8086/api/employees/";
            Uri    uriForNewEmployee = new Uri(new Uri(requestUri), id.ToString());

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

            repository.Expect(x => x.Insert(null)).IgnoreArguments().Repeat.Once();

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

            uow.Expect(x => x.Save()).Return(1).Repeat.Once();

            Mapper.CreateMap <EmployeeDto, Employee>();

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

            controller.SetRequest("employees", HttpMethod.Post, requestUri);

            // Act
            HttpResponseMessage response = controller.Post(employeeDto);

            // Assert
            repository.VerifyAllExpectations();
            uow.VerifyAllExpectations();

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.AreEqual(uriForNewEmployee, response.Headers.Location);
        }
Esempio n. 32
0
        public new void SetUp()
        {
            _paymentSettings = new PaymentSettings();
            _paymentSettings.ActivePaymentMethodSystemNames = new List <string>();
            _paymentSettings.ActivePaymentMethodSystemNames.Add("Payments.TestMethod");

            _storeMappingRepository = MockRepository.GenerateMock <IRepository <StoreMapping> >();
            _storeMappingService    = MockRepository.GenerateMock <IStoreMappingService>();
            _cartRuleProvider       = MockRepository.GenerateMock <ICartRuleProvider>();

            _services = MockRepository.GenerateMock <ICommonServices>();
            _services.Expect(x => x.RequestCache).Return(NullRequestCache.Instance);

            var paymentMethods = new List <PaymentMethod> {
                new PaymentMethod {
                    PaymentMethodSystemName = "Payments.TestMethod"
                }
            };

            _paymentMethodRepository = MockRepository.GenerateMock <IRepository <PaymentMethod> >();
            _paymentMethodRepository.Expect(x => x.TableUntracked).Return(paymentMethods.AsQueryable());

            _typeFinder = MockRepository.GenerateMock <ITypeFinder>();
            _typeFinder.Expect(x => x.FindClassesOfType((Type)null, null, true)).IgnoreArguments().Return(Enumerable.Empty <Type>()).Repeat.Any();

            var localizationService = MockRepository.GenerateMock <ILocalizationService>();

            localizationService.Expect(ls => ls.GetResource(null)).IgnoreArguments().Return("NotSupported").Repeat.Any();

            _paymentService = new PaymentService(_paymentMethodRepository, _storeMappingRepository, _storeMappingService, _paymentSettings, _cartRuleProvider,
                                                 this.ProviderManager, _services, _typeFinder);
        }
        public new void SetUp()
        {
            _discountRepo = MockRepository.GenerateMock <IRepository <Discount> >();
            var discount1 = new Discount
            {
                Id                 = 1,
                DiscountType       = DiscountType.AssignedToCategories,
                Name               = "Discount 1",
                UsePercentage      = true,
                DiscountPercentage = 10,
                DiscountAmount     = 0,
                DiscountLimitation = DiscountLimitationType.Unlimited,
                LimitationTimes    = 0,
            };
            var discount2 = new Discount
            {
                Id                 = 2,
                DiscountType       = DiscountType.AssignedToSkus,
                Name               = "Discount 2",
                UsePercentage      = false,
                DiscountPercentage = 0,
                DiscountAmount     = 5,
                RequiresCouponCode = true,
                CouponCode         = "SecretCode",
                DiscountLimitation = DiscountLimitationType.NTimesPerCustomer,
                LimitationTimes    = 3,
            };

            _discountRepo.Expect(x => x.Table).Return(new List <Discount> {
                discount1, discount2
            }.AsQueryable());

            _eventPublisher = MockRepository.GenerateMock <IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg <object> .Is.Anything));

            _storeContext = MockRepository.GenerateMock <IStoreContext>();

            _categoryRepo = MockRepository.GenerateMock <IRepository <Category> >();
            _categoryRepo.Expect(x => x.Table).Return(new List <Category>().AsQueryable());
            _manufacturerRepo = MockRepository.GenerateMock <IRepository <Manufacturer> >();
            _manufacturerRepo.Expect(x => x.Table).Return(new List <Manufacturer>().AsQueryable());
            _productRepo = MockRepository.GenerateMock <IRepository <Product> >();
            _productRepo.Expect(x => x.Table).Return(new List <Product>().AsQueryable());

            var cacheManager = new NopNullCache();

            _discountRequirementRepo = MockRepository.GenerateMock <IRepository <DiscountRequirement> >();
            _discountRequirementRepo.Expect(x => x.Table).Return(new List <DiscountRequirement>().AsQueryable());

            _discountUsageHistoryRepo = MockRepository.GenerateMock <IRepository <DiscountUsageHistory> >();
            var pluginFinder = new PluginFinder(_eventPublisher);

            _localizationService = MockRepository.GenerateMock <ILocalizationService>();
            _categoryService     = MockRepository.GenerateMock <ICategoryService>();

            _discountService = new DiscountService(cacheManager, _discountRepo, _discountRequirementRepo,
                                                   _discountUsageHistoryRepo, _categoryRepo, _manufacturerRepo, _productRepo, _storeContext,
                                                   _localizationService, _categoryService, pluginFinder, _eventPublisher);
        }
Esempio n. 34
0
        public async void WillReturnFalseWhenTokenRepositoryReturnsEmptyTokenStringOnIsUserLoggedInAsync()
        {
            var logic = new LoginLogic(_oAuthManager, null, _tokenRepository, _userRepository, _preferencesRepository, _updateRepository);

            _tokenRepository.Expect(t => t.Get()).Return(new Token {
                TokenString = null,
                Secret      = null
            });
            _userRepository.Expect(t => t.Get()).Return(null);

            var applyUser = new Action <User>(delegate { });

            Assert.IsFalse(await logic.IsUserLoggedInAsync(applyUser));

            _tokenRepository.VerifyAllExpectations();
            _userRepository.VerifyAllExpectations();
        }
        public static IRepository <Territory> CreateMockTerritoryRepository()
        {
            IRepository <Territory> mockedRepository = MockRepository.GenerateMock <IRepository <Territory> >();

            mockedRepository.Expect(mr => mr.GetAll()).Return(CreateTerritories());

            return(mockedRepository);
        }
        public void Setup()
        {
            _cacheManger = new NopNullCache();
            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _solFunRepository = MockRepository.GenerateMock<IRepository<SolutionFunder>>();

            var solfun1 = new SolutionFunder() { Id = 1, SolutionID = 1, SupplierID = 1 };
            var solfun2 = new SolutionFunder() { Id = 2, SolutionID = 2, SupplierID = 1 };
            var solfun3 = new SolutionFunder() { Id = 3, SolutionID = 1, SupplierID = 2 };
            var solfun4 = new SolutionFunder() { Id = 4, SolutionID = 2, SupplierID = 2 };
            var solfun5 = new SolutionFunder() { Id = 5, SolutionID = 3, SupplierID = 2 };
            var solfun6 = new SolutionFunder() { Id = 6, SolutionID = 4, SupplierID = 3 };

            _solFunRepository.Expect(s => s.Table).Return(new List<SolutionFunder> { solfun1, solfun2, solfun3, solfun4, solfun5, solfun6 }.AsQueryable());
            _solFunRepository.Expect(s => s.TableNoTracking).Return(new List<SolutionFunder> { solfun1, solfun2, solfun3, solfun4, solfun5, solfun6 }.AsQueryable());

            _solutionFunderService = new SolutionFunderService(_cacheManger, _solFunRepository, _eventPublisher);
        }
 public void Setup()
 {
     _field = ObjectMother.ValidField("raif").WithEntityId(1);
     _field.Size = 1000;
     _product = ObjectMother.ValidInventoryProductFertilizer("poop").WithEntityId(2);
     _product.SizeOfUnit = 100;
     _product.UnitType = UnitType.Lbs.ToString();
     var given = new SuperInputCalcViewModel
                     {
                         Field = _field.EntityId.ToString(),
                         Product = _product.EntityId.ToString(),
                         FertilizerRate = 100
                     };
     _repo = MockRepository.GenerateMock<IRepository>();
     _repo.Expect(x => x.Find<Field>(Int64.Parse(given.Field))).Return(_field);
     _repo.Expect(x => x.Find<InventoryProduct>(Int64.Parse(given.Product))).Return(_product);
     _SUT = new FertilizerNeededCalculator(_repo, new UnitSizeTimesQuantyCalculator(),null);
     _result = _SUT.Calculate(given);
 }
Esempio n. 38
0
 public new void SetUp()
 {
     _activityType1 = new ActivityLogType
     {
         Id = 1,
         SystemKeyword = "TestKeyword1",
         Enabled = true,
         Name = "Test name1"
     };
     _activityType2 = new ActivityLogType
     {
         Id = 2,
         SystemKeyword = "TestKeyword2",
         Enabled = true,
         Name = "Test name2"
     };
     _customer1 = new Customer
     {
         Id = 1,
         Email = "*****@*****.**",
         Username = "******",
         Deleted = false,
     };
    _customer2 = new Customer
    {
        Id = 2,
        Email = "*****@*****.**",
        Username = "******",
        Deleted = false,
    };
     _activity1 = new ActivityLog
     {
         Id = 1,
         ActivityLogType = _activityType1,
         CustomerId = _customer1.Id,
         Customer = _customer1
     };
     _activity2 = new ActivityLog
     {
         Id = 2,
         ActivityLogType = _activityType1,
         CustomerId = _customer2.Id,
         Customer = _customer2
     };
     _cacheManager = new NopNullCache();
     _workContext = MockRepository.GenerateMock<IWorkContext>();
     _webHelper = MockRepository.GenerateMock<IWebHelper>();
     _activityLogRepository = MockRepository.GenerateMock<IRepository<ActivityLog>>();
     _activityLogTypeRepository = MockRepository.GenerateMock<IRepository<ActivityLogType>>();
     _activityLogTypeRepository.Expect(x => x.Table).Return(new List<ActivityLogType> { _activityType1, _activityType2 }.AsQueryable());
     _activityLogRepository.Expect(x => x.Table).Return(new List<ActivityLog> { _activity1, _activity2 }.AsQueryable());
     _customerActivityService = new CustomerActivityService(_cacheManager, _activityLogRepository, _activityLogTypeRepository, _workContext, null, null, null, _webHelper);
 }
        public new void SetUp()
        {
            _discountRepo = MockRepository.GenerateMock<IRepository<Discount>>();
            var discount1 = new Discount
            {
                Id = 1,
                DiscountType = DiscountType.AssignedToCategories,
                Name = "Discount 1",
                UsePercentage = true,
                DiscountPercentage = 10,
                DiscountAmount = 0,
                DiscountLimitation = DiscountLimitationType.Unlimited,
                LimitationTimes = 0,
            };
            var discount2 = new Discount
            {
                Id = 2,
                DiscountType = DiscountType.AssignedToSkus,
                Name = "Discount 2",
                UsePercentage = false,
                DiscountPercentage = 0,
                DiscountAmount = 5,
                RequiresCouponCode = true,
                CouponCode = "SecretCode",
                DiscountLimitation = DiscountLimitationType.NTimesPerCustomer,
                LimitationTimes = 3,
            };

            _discountRepo.Expect(x => x.Table).Return(new List<Discount>() { discount1, discount2 }.AsQueryable());

            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));

			_storeContext = MockRepository.GenerateMock<IStoreContext>();
			_storeContext.Expect(x => x.CurrentStore).Return(new Store 
			{ 
				Id = 1,
				Name = "MyStore"
			});

			_settingService = MockRepository.GenerateMock<ISettingService>();

            var cacheManager = new NullCache();
            _discountRequirementRepo = MockRepository.GenerateMock<IRepository<DiscountRequirement>>();
            _discountUsageHistoryRepo = MockRepository.GenerateMock<IRepository<DiscountUsageHistory>>();
            var pluginFinder = new PluginFinder();
			_genericAttributeService = MockRepository.GenerateMock<IGenericAttributeService>();

			_discountService = new DiscountService(cacheManager, _discountRepo, _discountRequirementRepo,
				_discountUsageHistoryRepo, _storeContext, _genericAttributeService, pluginFinder, _eventPublisher,
				_settingService, base.ProviderManager);
        }
        public new void SetUp()
        {
            var cacheManager = new NopNullCache();

            _workContext = null;

            _currencySettings = new CurrencySettings();
            var currency1 = new Currency
            {
                Id = 1,
                Name = "Euro",
                CurrencyCode = "EUR",
                DisplayLocale =  "",
                CustomFormatting = "€0.00",
                DisplayOrder = 1,
                Published = true,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc= DateTime.UtcNow
            };
            var currency2 = new Currency
            {
                Id = 1,
                Name = "US Dollar",
                CurrencyCode = "USD",
                DisplayLocale = "en-US",
                CustomFormatting = "",
                DisplayOrder = 2,
                Published = true,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc= DateTime.UtcNow
            };            
            _currencyRepo = MockRepository.GenerateMock<IRepository<Currency>>();
            _currencyRepo.Expect(x => x.Table).Return(new List<Currency>() { currency1, currency2 }.AsQueryable());

            _storeMappingService = MockRepository.GenerateMock<IStoreMappingService>();

            var pluginFinder = new PluginFinder();
            _currencyService = new CurrencyService(cacheManager, _currencyRepo, _storeMappingService,
                _currencySettings, pluginFinder, null);

            _taxSettings = new TaxSettings();

            _localizationService = MockRepository.GenerateMock<ILocalizationService>();
            _localizationService.Expect(x => x.GetResource("Products.InclTaxSuffix", 1, false)).Return("{0} incl tax");
            _localizationService.Expect(x => x.GetResource("Products.ExclTaxSuffix", 1, false)).Return("{0} excl tax");
            
            _priceFormatter = new PriceFormatter(_workContext, _currencyService,_localizationService, 
                _taxSettings, _currencySettings);
        }
 public void Setup()
 {
     _poliId = 0;
     _repo = MockRepository.GenerateMock<IRepository>();
     _purchaseOrderLineItem = ObjectMother.ValidPurchaseOrderLineItem("raif");
     _inventoryBaseProducts = new List<InventoryProduct> { ObjectMother.ValidInventoryBaseProduct("raif")}.AsQueryable();
     _purchaseOrderLineItem.TotalReceived = 4;
     _repo.Expect(x => x.Query<InventoryProduct>(null)).IgnoreArguments().Return(_inventoryBaseProducts);
     _saveEntityService = MockRepository.GenerateMock<ISaveEntityService>();
     _crudManager = MockRepository.GenerateMock<ICrudManager>();
     _crudManager.Expect(x => x.Finish()).Return(new Notification());
     _sesCatcher = _saveEntityService.CaptureArgumentsFor(x=>x.ProcessSave(_inventoryBaseProducts.FirstOrDefault(),null),x=>x.Return(_crudManager));
     _SUT = new InventoryService(_repo, _saveEntityService);
      _crudManager = _SUT.ReceivePurchaseOrderLineItem(_purchaseOrderLineItem);
 }
        public void Setup()
        {
            _cacheManger = new NopNullCache();
            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _solFunFeaRepository = MockRepository.GenerateMock<IRepository<SolutionFeature>>();

            var solfunfea1 = new SolutionFeature() { Id = 1, FeatureId = 1 };
            var solfunfea2 = new SolutionFeature() { Id = 2, FeatureId = 1 };
            var solfunfea3 = new SolutionFeature() { Id = 3, FeatureId = 1 };
            var solfunfea4 = new SolutionFeature() { Id = 4, FeatureId = 2 };
            var solfunfea5 = new SolutionFeature() { Id = 5, FeatureId = 2 };

            _solFunFeaRepository.Expect(s => s.TableNoTracking).Return(new List<SolutionFeature> { solfunfea1, solfunfea2, solfunfea3, solfunfea4, solfunfea5 }.AsQueryable());
            _solutionFunderFeatureService = new SolutionFunderFeatureService(_cacheManger, _solFunFeaRepository, _eventPublisher);
        }
 public void Setup()
 {
     _field = ObjectMother.ValidField("raif").WithEntityId(1);
     _field.Size = 1000;
     var given = new SuperInputCalcViewModel
     {
         Field = _field.EntityId.ToString(),
         Depth = 10,
         DitchDepth = 10,
         DitchlineWidth = 10,
         Drainageline = 10,
         PipeRadius = 10
     };
     _repo = MockRepository.GenerateMock<IRepository>();
     _repo.Expect(x => x.Find<Field>(Int64.Parse(given.Field))).Return(_field);
     _SUT = new MaterialsCalculator(_repo, null);
     _result = _SUT.Calculate(given);
 }
        public void SetUp()
        {
            // you have to be an administrator to access the order controller
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin"), new[] { "Administrator" });

            orderRepository = MockRepository.GenerateStub<IRepository<Order>>();
            countryRepository = MockRepository.GenerateStub<IRepository<Country>>();
            cardTypeRepository = MockRepository.GenerateStub<IRepository<CardType>>();
			

            encryptionService = MockRepository.GenerateStub<IEncryptionService>();
            postageService = MockRepository.GenerateStub<IPostageService>();
            userService = MockRepository.GenerateStub<IUserService>();
			searchService = MockRepository.GenerateStub<IOrderSearchService>();

            var mocks = new MockRepository();
    		statusRepository = MockRepository.GenerateStub<IRepository<OrderStatus>>();
    		orderController = new OrderController(
                orderRepository,
                countryRepository,
                cardTypeRepository,
                encryptionService,
                postageService,
                userService,
				searchService,
				statusRepository
				);

            testContext = new ControllerTestContext(orderController);

            postageService.Expect(ps => ps.CalculatePostageFor(Arg<Order>.Is.Anything));

            userService.Expect(us => us.CurrentUser).Return(new User { UserId = 4, RoleId = Role.AdministratorId });

            testContext.TestContext.Context.User = new User { UserId = 4 };
            testContext.TestContext.Request.RequestType = "GET";
            testContext.TestContext.Request.Stub(r => r.QueryString).Return(new NameValueCollection());
            testContext.TestContext.Request.Stub(r => r.Form).Return(new NameValueCollection());
			statusRepository.Expect(x => x.GetAll()).Return(new List<OrderStatus>().AsQueryable());

            mocks.ReplayAll();
        }
            public void BeforeEachTest()
            {
                _repository = MockRepository.GenerateMock<IRepository>();
                sampleService = new SampleService(_repository);

                _expectedBook = new Book
                                    {
                                        Title = "Book",
                                        Price = 10m
                                    };

                _expectedAuthor = new Author
                                      {
                                          Name = "Author"
                                      };

                _repository.Expect(x => x.Save(_expectedBook)).Repeat.Once();

                _actualBook = sampleService.UpdateBook(_expectedBook, _expectedAuthor);
            }
        public void SetUp()
        {
            _solutionBPCalculationRepo = MockRepository.GenerateMock<IRepository<SolutionBPCalculation>>();

            var configCurrent = new SolutionBPCalculationConfig
            {
                IsCurrent = true
            };

            var config2 = new SolutionBPCalculationConfig
            {
                IsCurrent = false
            };

            var entity1 = new SolutionBPCalculation
            {
                Id = 1,
                BPTypeID = 1,
                CalculationConfigID = 1,
                Calculation = "Calculation",
                BPTypeMLL = "BPTypeMLL",
                SolutionBPCalculationConfig = config2
            };

            var entity2 = new SolutionBPCalculation
            {
                Id = 2,
                BPTypeID = 1,
                CalculationConfigID = 1,
                Calculation = "Current Calculation",
                BPTypeMLL = "BPTypeMLL",
                SolutionBPCalculationConfig = configCurrent
            };

            var entity3 = new SolutionBPCalculation
            {
                Id = 3,
                BPTypeID = 2,
                CalculationConfigID = 2,
                Calculation = "Calculation",
                BPTypeMLL = "BPTypeMLL",
                SolutionBPCalculationConfig = config2
            };

            var cacheManager = new NopNullCache();
            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));

            _solutionBPCalculationRepo.Expect(x => x.Table).Return(new List<SolutionBPCalculation> { entity1, entity2, entity3}.AsQueryable());
            _solutionBPCalculationService = new SolutionBPCalculationService(cacheManager, _solutionBPCalculationRepo, _eventPublisher);
        }
        public new void SetUp()
        {
            #region Test data

            //color (dropdownlist)
            pa1 = new ProductAttribute
            {
                Id = 1,
                Name = "Color",
            };
            pva1_1 = new ProductVariantAttribute
            {
                Id = 11,
                ProductVariantId = 1,
                TextPrompt = "Select color:",
                IsRequired = true,
                AttributeControlType = AttributeControlType.DropdownList,
                DisplayOrder = 1,
                ProductAttribute = pa1,
                ProductAttributeId = pa1.Id
            };
            pvav1_1 = new ProductVariantAttributeValue
            {
                Id = 11,
                Name = "Green",
                DisplayOrder = 1,
                ProductVariantAttribute = pva1_1,
                ProductVariantAttributeId = pva1_1.Id
            };
            pvav1_2 = new ProductVariantAttributeValue
            {
                Id = 12,
                Name = "Red",
                DisplayOrder = 2,
                ProductVariantAttribute = pva1_1,
                ProductVariantAttributeId = pva1_1.Id
            };
            pva1_1.ProductVariantAttributeValues.Add(pvav1_1);
            pva1_1.ProductVariantAttributeValues.Add(pvav1_2);

            //custom option (checkboxes)
            pa2 = new ProductAttribute
            {
                Id = 2,
                Name = "Some custom option",
            };
            pva2_1 = new ProductVariantAttribute
            {
                Id = 21,
                ProductVariantId = 1,
                TextPrompt = "Select at least one option:",
                IsRequired = true,
                AttributeControlType = AttributeControlType.Checkboxes,
                DisplayOrder = 2,
                ProductAttribute = pa2,
                ProductAttributeId = pa2.Id
            };
            pvav2_1 = new ProductVariantAttributeValue
            {
                Id = 21,
                Name = "Option 1",
                DisplayOrder = 1,
                ProductVariantAttribute = pva2_1,
                ProductVariantAttributeId = pva2_1.Id
            };
            pvav2_2 = new ProductVariantAttributeValue
            {
                Id = 22,
                Name = "Option 2",
                DisplayOrder = 2,
                ProductVariantAttribute = pva2_1,
                ProductVariantAttributeId = pva2_1.Id
            };
            pva2_1.ProductVariantAttributeValues.Add(pvav2_1);
            pva2_1.ProductVariantAttributeValues.Add(pvav2_2);

            //custom text
            pa3 = new ProductAttribute
            {
                Id = 3,
                Name = "Custom text",
            };
            pva3_1 = new ProductVariantAttribute
            {
                Id = 31,
                ProductVariantId = 1,
                TextPrompt = "Enter custom text:",
                IsRequired = true,
                AttributeControlType = AttributeControlType.TextBox,
                DisplayOrder = 1,
                ProductAttribute = pa1,
                ProductAttributeId = pa3.Id
            };

            #endregion

            _productAttributeRepo = MockRepository.GenerateMock<IRepository<ProductAttribute>>();
            _productAttributeRepo.Expect(x => x.Table).Return(new List<ProductAttribute>() { pa1, pa2, pa3 }.AsQueryable());
            _productAttributeRepo.Expect(x => x.GetById(pa1.Id)).Return(pa1);
            _productAttributeRepo.Expect(x => x.GetById(pa2.Id)).Return(pa2);
            _productAttributeRepo.Expect(x => x.GetById(pa3.Id)).Return(pa3);

            _productVariantAttributeRepo = MockRepository.GenerateMock<IRepository<ProductVariantAttribute>>();
            _productVariantAttributeRepo.Expect(x => x.Table).Return(new List<ProductVariantAttribute>() { pva1_1, pva2_1, pva3_1 }.AsQueryable());
            _productVariantAttributeRepo.Expect(x => x.GetById(pva1_1.Id)).Return(pva1_1);
            _productVariantAttributeRepo.Expect(x => x.GetById(pva2_1.Id)).Return(pva2_1);
            _productVariantAttributeRepo.Expect(x => x.GetById(pva3_1.Id)).Return(pva3_1);

            _productVariantAttributeCombinationRepo = MockRepository.GenerateMock<IRepository<ProductVariantAttributeCombination>>();
            _productVariantAttributeCombinationRepo.Expect(x => x.Table).Return(new List<ProductVariantAttributeCombination>().AsQueryable());

            _productVariantAttributeValueRepo = MockRepository.GenerateMock<IRepository<ProductVariantAttributeValue>>();
            _productVariantAttributeValueRepo.Expect(x => x.Table).Return(new List<ProductVariantAttributeValue>() { pvav1_1, pvav1_2, pvav2_1, pvav2_2 }.AsQueryable());
            _productVariantAttributeValueRepo.Expect(x => x.GetById(pvav1_1.Id)).Return(pvav1_1);
            _productVariantAttributeValueRepo.Expect(x => x.GetById(pvav1_2.Id)).Return(pvav1_2);
            _productVariantAttributeValueRepo.Expect(x => x.GetById(pvav2_1.Id)).Return(pvav2_1);
            _productVariantAttributeValueRepo.Expect(x => x.GetById(pvav2_2.Id)).Return(pvav2_2);

            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));

            var cacheManager = new NasNullCache();

            _productAttributeService = new ProductAttributeService(cacheManager,
                _productAttributeRepo,
                _productVariantAttributeRepo,
                _productVariantAttributeCombinationRepo,
                _productVariantAttributeValueRepo,
                _eventPublisher);

            _productAttributeParser = new ProductAttributeParser(_productAttributeService);

            var workingLanguage = new Language();
            _workContext = MockRepository.GenerateMock<IWorkContext>();
            _workContext.Expect(x => x.WorkingLanguage).Return(workingLanguage);
            _currencyService = MockRepository.GenerateMock<ICurrencyService>();
            _localizationService = MockRepository.GenerateMock<ILocalizationService>();
            _localizationService.Expect(x => x.GetResource("GiftCardAttribute.For.Virtual")).Return("For: {0} <{1}>");
            _localizationService.Expect(x => x.GetResource("GiftCardAttribute.From.Virtual")).Return("From: {0} <{1}>");
            _localizationService.Expect(x => x.GetResource("GiftCardAttribute.For.Physical")).Return("For: {0}");
            _localizationService.Expect(x => x.GetResource("GiftCardAttribute.From.Physical")).Return("From: {0}");
            _taxService = MockRepository.GenerateMock<ITaxService>();
            _priceFormatter = MockRepository.GenerateMock<IPriceFormatter>();
            _downloadService = MockRepository.GenerateMock<IDownloadService>();
            _webHelper = MockRepository.GenerateMock<IWebHelper>();

            _productAttributeFormatter = new ProductAttributeFormatter(_workContext,
                _productAttributeService,
                _productAttributeParser,
                _currencyService,
                _localizationService,
                _taxService,
                _priceFormatter,
                _downloadService,
                _webHelper);
        }
        public static void RegistrationPetitions(int count, IRepository<RegistrationPetition> repository, List<RegistrationPetition> specificRegistrationPetitions)
        {
            var registrationPetitions = new List<RegistrationPetition>();
            var specificRegistrationPetitionsCount = 0;
            if (specificRegistrationPetitions != null)
            {
                specificRegistrationPetitionsCount = specificRegistrationPetitions.Count;
                for (int i = 0; i < specificRegistrationPetitionsCount; i++)
                {
                    registrationPetitions.Add(specificRegistrationPetitions[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                registrationPetitions.Add(CreateValidEntities.RegistrationPetition(i + specificRegistrationPetitionsCount + 1));
            }

            var totalCount = registrationPetitions.Count;
            for (int i = 0; i < totalCount; i++)
            {
                registrationPetitions[i].SetIdTo(i + 1);
                int i1 = i;
                repository
                    .Expect(a => a.GetNullableById(i1 + 1))
                    .Return(registrationPetitions[i])
                    .Repeat
                    .Any();
            }
            repository.Expect(a => a.GetNullableById(totalCount + 1)).Return(null).Repeat.Any();
            repository.Expect(a => a.Queryable).Return(registrationPetitions.AsQueryable()).Repeat.Any();
            repository.Expect(a => a.GetAll()).Return(registrationPetitions).Repeat.Any();
        }
        public static void FakevTermCode(int count, IRepository<vTermCode> termCodeRepository, List<vTermCode> specificTermCodes)
        {
            var termCodes = new List<vTermCode>();
            var specificTermCodesCount = 0;
            if (specificTermCodes != null)
            {
                specificTermCodesCount = specificTermCodes.Count;
                for (int i = 0; i < specificTermCodesCount; i++)
                {
                    termCodes.Add(specificTermCodes[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                termCodes.Add(CreateValidEntities.vTermCode(i + specificTermCodesCount + 1));
                termCodes[i + specificTermCodesCount].EndDate = DateTime.Now.AddDays((-2 + i)).Date;
            }

            var totalCount = termCodes.Count;
            for (int i = 0; i < totalCount; i++)
            {
                termCodes[i].SetIdTo((i + 1).ToString());
                //int i1 = i;
                //repository.OfType<State>()
                //    .Expect(a => a.GetNullableById(i1 + 1))
                //    .Return(TermCode[i])
                //    .Repeat
                //    .Any();
            }
            //State is not an Int Id, if I need to fake this, I'll need to pass a different repository
            //repository.OfType<TermCode>().Expect(a => a.GetNullableById(totalCount + 1)).Return(null).Repeat.Any();
            termCodeRepository.Expect(a => a.Queryable).Return(termCodes.AsQueryable()).Repeat.Any();
            termCodeRepository.Expect(a => a.GetAll()).Return(termCodes).Repeat.Any();
        }
Esempio n. 50
0
        public new void SetUp()
        {
            currencyUSD = new Currency()
            {
                Id = 1,
                Name = "US Dollar",
                CurrencyCode = "USD",
                Rate = 1.2M,
                DisplayLocale = "en-US",
                CustomFormatting = "",
                Published = true,
                DisplayOrder = 1,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
            };
            currencyEUR = new Currency()
            {
                Id = 2,
                Name = "Euro",
                CurrencyCode = "EUR",
                Rate = 1,
                DisplayLocale = "de-DE",
                CustomFormatting = "€0.00",
                Published = true,
                DisplayOrder = 2,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
            };
            currencyRUR = new Currency()
            {
                Id = 3,
                Name = "Russian Rouble",
                CurrencyCode = "RUB",
                Rate = 34.5M,
                DisplayLocale = "ru-RU",
                CustomFormatting = "",
                Published = true,
                DisplayOrder = 3,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
            };

            _currencyRepository = MockRepository.GenerateMock<IRepository<Currency>>();
            _currencyRepository.Expect(x => x.Table).Return(new List<Currency>() { currencyUSD, currencyEUR, currencyRUR }.AsQueryable());
            _currencyRepository.Expect(x => x.GetById(currencyUSD.Id)).Return(currencyUSD);
            _currencyRepository.Expect(x => x.GetById(currencyEUR.Id)).Return(currencyEUR);
            _currencyRepository.Expect(x => x.GetById(currencyRUR.Id)).Return(currencyRUR);

            _storeMappingService = MockRepository.GenerateMock<IStoreMappingService>();
            _storeContext = MockRepository.GenerateMock<IStoreContext>();

            var cacheManager = new NullCache();

            _currencySettings = new CurrencySettings();

            _storeContext.Expect(x => x.CurrentStore).Return(new Store
            {
                Name = "Computer store",
                Url = "http://www.yourStore.com",
                Hosts = "yourStore.com,www.yourStore.com",
                PrimaryStoreCurrency = currencyUSD,
                PrimaryExchangeRateCurrency = currencyEUR
            });

            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));

            var pluginFinder = new PluginFinder();
            _currencyService = new CurrencyService(cacheManager, _currencyRepository, _storeMappingService,
                _currencySettings, pluginFinder, _eventPublisher, this.ProviderManager, _storeContext);
        }
        /// <summary>
        /// Fakes the student. Note: Using more than 20 will not be reliable
        /// because the Guids will be random
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="studentRepository">The student repository.</param>
        /// <param name="specificStudents">The specific students.</param>
        /// <param name="studentRepository2">The student repository2.</param>
        public static void FakeStudent(int count, IRepositoryWithTypedId<Student, Guid> studentRepository, List<Student> specificStudents, IRepository<Student> studentRepository2)
        {
            var students = new List<Student>();
            var specificStudentsCount = 0;
            if (specificStudents != null)
            {
                specificStudentsCount = specificStudents.Count;
                for (int i = 0; i < specificStudentsCount; i++)
                {
                    students.Add(specificStudents[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                students.Add(CreateValidEntities.Student(i + specificStudentsCount + 1));
            }

            var totalCount = students.Count;
            for (int i = 0; i < totalCount; i++)
            {
                students[i].SetIdTo(SpecificGuid.GetGuid(i+1));
                int i1 = i;
                studentRepository
                    .Expect(a => a.GetNullableById(students[i1].Id))
                    .Return(students[i])
                    .Repeat
                    .Any();
            }
            studentRepository.Expect(a => a.GetNullableById(SpecificGuid.GetGuid(totalCount + 1))).Return(null).Repeat.Any();
            studentRepository.Expect(a => a.Queryable).Return(students.AsQueryable()).Repeat.Any();
            studentRepository.Expect(a => a.GetAll()).Return(students).Repeat.Any();
            if(studentRepository2 != null)
            {
                studentRepository2.Expect(a => a.Queryable).Return(students.AsQueryable()).Repeat.Any();
                studentRepository2.Expect(a => a.GetAll()).Return(students).Repeat.Any();
            }
        }
        public static void FakeSpecialNeeds(int count, IRepository<SpecialNeed> repository, List<SpecialNeed> specificSpecialNeeds)
        {
            var specialNeeds = new List<SpecialNeed>();
            var specificSpecialNeedsCount = 0;
            if (specificSpecialNeeds != null)
            {
                specificSpecialNeedsCount = specificSpecialNeeds.Count;
                for (int i = 0; i < specificSpecialNeedsCount; i++)
                {
                    specialNeeds.Add(specificSpecialNeeds[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                specialNeeds.Add(CreateValidEntities.SpecialNeed(i + specificSpecialNeedsCount + 1));
            }

            var totalCount = specialNeeds.Count;
            for (int i = 0; i < totalCount; i++)
            {
                specialNeeds[i].SetIdTo(i + 1);
                int i1 = i;
                repository
                    .Expect(a => a.GetNullableById(i1 + 1))
                    .Return(specialNeeds[i])
                    .Repeat
                    .Any();
            }
            repository.Expect(a => a.GetNullableById(totalCount + 1)).Return(null).Repeat.Any();
            repository.Expect(a => a.Queryable).Return(specialNeeds.AsQueryable()).Repeat.Any();
            repository.Expect(a => a.GetAll()).Return(specialNeeds).Repeat.Any();
        }
        public new void SetUp()
        {
            _customerSettings = new CustomerSettings();
            _securitySettings = new SecuritySettings()
            {
                EncryptionKey = "273ece6f97dd844d"
            };
            _rewardPointsSettings = new RewardPointsSettings()
            {
                Enabled = false,
            };

            _encryptionService = new EncryptionService(_securitySettings);
            _customerRepo = MockRepository.GenerateMock<IRepository<Customer>>();
            var customer1 = new Customer()
            {
                Username = "******",
                Email = "*****@*****.**",
                PasswordFormat = PasswordFormat.Hashed,
                Active = true
            };

            string saltKey = _encryptionService.CreateSaltKey(5);
            string password = _encryptionService.CreatePasswordHash("password", saltKey);
            customer1.PasswordSalt = saltKey;
            customer1.Password = password;
            AddCustomerToRegisteredRole(customer1);

            var customer2 = new Customer()
            {
                Username = "******",
                Email = "*****@*****.**",
                PasswordFormat = PasswordFormat.Clear,
                Password = "******",
                Active = true
            };
            AddCustomerToRegisteredRole(customer2);

            var customer3 = new Customer()
            {
                Username = "******",
                Email = "*****@*****.**",
                PasswordFormat = PasswordFormat.Encrypted,
                Password = _encryptionService.EncryptText("password"),
                Active = true
            };
            AddCustomerToRegisteredRole(customer3);

            var customer4 = new Customer()
            {
                Username = "******",
                Email = "*****@*****.**",
                PasswordFormat = PasswordFormat.Clear,
                Password = "******",
                Active = true
            };
            AddCustomerToRegisteredRole(customer4);

            var customer5 = new Customer()
            {
                Username = "******",
                Email = "*****@*****.**",
                PasswordFormat = PasswordFormat.Clear,
                Password = "******",
                Active = true
            };

            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));

            _customerRepo.Expect(x => x.Table).Return(new List<Customer>() { customer1, customer2, customer3, customer4, customer5 }.AsQueryable());

            _customerRoleRepo = MockRepository.GenerateMock<IRepository<CustomerRole>>();
            _genericAttributeRepo = MockRepository.GenerateMock<IRepository<GenericAttribute>>();

            _genericAttributeService = MockRepository.GenerateMock<IGenericAttributeService>();
            _newsLetterSubscriptionService = MockRepository.GenerateMock<INewsLetterSubscriptionService>();

            _localizationService = MockRepository.GenerateMock<ILocalizationService>();
            _customerService = new CustomerService(new NopNullCache(), _customerRepo, _customerRoleRepo,
                _genericAttributeRepo, _genericAttributeService, _eventPublisher, _customerSettings);
            _customerRegistrationService = new CustomerRegistrationService(_customerService,
                _encryptionService, _newsLetterSubscriptionService, _localizationService,
                _rewardPointsSettings, _customerSettings);
        }
Esempio n. 54
0
        public new void SetUp()
        {
            measureDimension1 = new MeasureDimension()
            {
                Id = 1,
                Name = "inch(es)",
                SystemKeyword = "inches",
                Ratio = 1M,
                DisplayOrder = 1,
            };
            measureDimension2 = new MeasureDimension()
            {
                Id = 2,
                Name = "feet",
                SystemKeyword = "feet",
                Ratio = 0.08333333M,
                DisplayOrder = 2,
            };
            measureDimension3 = new MeasureDimension()
            {
                Id = 3,
                Name = "meter(s)",
                SystemKeyword = "meters",
                Ratio = 0.0254M,
                DisplayOrder = 3,
            };
            measureDimension4 = new MeasureDimension()
            {
                Id = 4,
                Name = "millimetre(s)",
                SystemKeyword = "millimetres",
                Ratio = 25.4M,
                DisplayOrder = 4,
            };

            measureWeight1 = new MeasureWeight()
            {
                Id = 1,
                Name = "ounce(s)",
                SystemKeyword = "ounce",
                Ratio = 16M,
                DisplayOrder = 1,
            };
            measureWeight2 = new MeasureWeight()
            {
                Id = 2,
                Name = "lb(s)",
                SystemKeyword = "lb",
                Ratio = 1M,
                DisplayOrder = 2,
            };
            measureWeight3 = new MeasureWeight()
            {
                Id = 3,
                Name = "kg(s)",
                SystemKeyword = "kg",
                Ratio = 0.45359237M,
                DisplayOrder = 3,
            };
            measureWeight4 = new MeasureWeight()
            {
                Id = 4,
                Name = "gram(s)",
                SystemKeyword = "grams",
                Ratio = 453.59237M,
                DisplayOrder = 4,
            };

            _measureDimensionRepository = MockRepository.GenerateMock<IRepository<MeasureDimension>>();
            _measureDimensionRepository.Expect(x => x.Table).Return(new List<MeasureDimension>() { measureDimension1, measureDimension2, measureDimension3, measureDimension4 }.AsQueryable());
            _measureDimensionRepository.Expect(x => x.GetById(measureDimension1.Id)).Return(measureDimension1);
            _measureDimensionRepository.Expect(x => x.GetById(measureDimension2.Id)).Return(measureDimension2);
            _measureDimensionRepository.Expect(x => x.GetById(measureDimension3.Id)).Return(measureDimension3);
            _measureDimensionRepository.Expect(x => x.GetById(measureDimension4.Id)).Return(measureDimension4);

            _measureWeightRepository = MockRepository.GenerateMock<IRepository<MeasureWeight>>();
            _measureWeightRepository.Expect(x => x.Table).Return(new List<MeasureWeight>() { measureWeight1, measureWeight2, measureWeight3, measureWeight4 }.AsQueryable());
            _measureWeightRepository.Expect(x => x.GetById(measureWeight1.Id)).Return(measureWeight1);
            _measureWeightRepository.Expect(x => x.GetById(measureWeight2.Id)).Return(measureWeight2);
            _measureWeightRepository.Expect(x => x.GetById(measureWeight3.Id)).Return(measureWeight3);
            _measureWeightRepository.Expect(x => x.GetById(measureWeight4.Id)).Return(measureWeight4);

            var cacheManager = new NasNullCache();

            _measureSettings = new MeasureSettings();
            _measureSettings.BaseDimensionId = measureDimension1.Id; //inch(es)
            _measureSettings.BaseWeightId = measureWeight2.Id; //lb(s)

            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));

            _measureService = new MeasureService(cacheManager,
                _measureDimensionRepository,
                _measureWeightRepository,
                _measureSettings, _eventPublisher);
        }
        public new void SetUp()
        {
            currencyUSD = new Currency()
            {
                Id = 1,
                Name = "US Dollar",
                CurrencyCode = "USD",
                Rate = 1.2M,
                DisplayLocale = "en-US",
                CustomFormatting = "",
                Published = true,
                DisplayOrder = 1,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
            };
            currencyEUR = new Currency()
            {
                Id = 2,
                Name = "Euro",
                CurrencyCode = "EUR",
                Rate = 1,
                DisplayLocale = "",
                CustomFormatting = "€0.00",
                Published = true,
                DisplayOrder = 2,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
            };
            currencyRUR = new Currency()
            {
                Id = 3,
                Name = "Russian Rouble",
                CurrencyCode = "RUB",
                Rate = 34.5M,
                DisplayLocale = "ru-RU",
                CustomFormatting = "",
                Published = true,
                DisplayOrder = 3,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
            };
            _currencyRepository = MockRepository.GenerateMock<IRepository<Currency>>();
            _currencyRepository.Expect(x => x.Table).Return(new List<Currency>() { currencyUSD, currencyEUR, currencyRUR }.AsQueryable());
            _currencyRepository.Expect(x => x.GetById(currencyUSD.Id)).Return(currencyUSD);
            _currencyRepository.Expect(x => x.GetById(currencyEUR.Id)).Return(currencyEUR);
            _currencyRepository.Expect(x => x.GetById(currencyRUR.Id)).Return(currencyRUR);

            var cacheManager = new NopNullCache();

            _customerService = MockRepository.GenerateMock<ICustomerService>();

            _currencySettings = new CurrencySettings();
            _currencySettings.PrimaryStoreCurrencyId = currencyUSD.Id;
            _currencySettings.PrimaryExchangeRateCurrencyId = currencyEUR.Id;

            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));

            var pluginFinder = new PluginFinder();
            _currencyService = new CurrencyService(cacheManager,
                _currencyRepository, _customerService,
                _currencySettings, pluginFinder, _eventPublisher);
        }
        public new void SetUp()
        {
            #region Test data

            //color (dropdownlist)
            ca1 = new CheckoutAttribute
            {
                Id = 1,
                Name= "Color",
                TextPrompt = "Select color:",
                IsRequired = true,
                AttributeControlType = AttributeControlType.DropdownList,
                DisplayOrder = 1,
            };
            cav1_1 = new CheckoutAttributeValue
            {
                Id = 11,
                Name = "Green",
                DisplayOrder = 1,
                CheckoutAttribute = ca1,
                CheckoutAttributeId = ca1.Id,
            };
            cav1_2 = new CheckoutAttributeValue
            {
                Id = 12,
                Name = "Red",
                DisplayOrder = 2,
                CheckoutAttribute = ca1,
                CheckoutAttributeId = ca1.Id,
            };
            ca1.CheckoutAttributeValues.Add(cav1_1);
            ca1.CheckoutAttributeValues.Add(cav1_2);

            //custom option (checkboxes)
            ca2 = new CheckoutAttribute
            {
                Id = 2,
                Name = "Custom option",
                TextPrompt = "Select custom option:",
                IsRequired = true,
                AttributeControlType = AttributeControlType.Checkboxes,
                DisplayOrder = 2,
            };
            cav2_1 = new CheckoutAttributeValue
            {
                Id = 21,
                Name = "Option 1",
                DisplayOrder = 1,
                CheckoutAttribute = ca2,
                CheckoutAttributeId = ca2.Id,
            };
            cav2_2 = new CheckoutAttributeValue
            {
                Id = 22,
                Name = "Option 2",
                DisplayOrder = 2,
                CheckoutAttribute = ca2,
                CheckoutAttributeId = ca2.Id,
            };
            ca2.CheckoutAttributeValues.Add(cav2_1);
            ca2.CheckoutAttributeValues.Add(cav2_2);

            //custom text
            ca3 = new CheckoutAttribute
            {
                Id = 3,
                Name = "Custom text",
                TextPrompt = "Enter custom text:",
                IsRequired = true,
                AttributeControlType = AttributeControlType.MultilineTextbox,
                DisplayOrder = 3,
            };

            #endregion

            _checkoutAttributeRepo = MockRepository.GenerateMock<IRepository<CheckoutAttribute>>();
            _checkoutAttributeRepo.Expect(x => x.Table).Return(new List<CheckoutAttribute> { ca1, ca2, ca3 }.AsQueryable());
            _checkoutAttributeRepo.Expect(x => x.GetById(ca1.Id)).Return(ca1);
            _checkoutAttributeRepo.Expect(x => x.GetById(ca2.Id)).Return(ca2);
            _checkoutAttributeRepo.Expect(x => x.GetById(ca3.Id)).Return(ca3);

            _checkoutAttributeValueRepo = MockRepository.GenerateMock<IRepository<CheckoutAttributeValue>>();
            _checkoutAttributeValueRepo.Expect(x => x.Table).Return(new List<CheckoutAttributeValue> { cav1_1, cav1_2, cav2_1, cav2_2 }.AsQueryable());
            _checkoutAttributeValueRepo.Expect(x => x.GetById(cav1_1.Id)).Return(cav1_1);
            _checkoutAttributeValueRepo.Expect(x => x.GetById(cav1_2.Id)).Return(cav1_2);
            _checkoutAttributeValueRepo.Expect(x => x.GetById(cav2_1.Id)).Return(cav2_1);
            _checkoutAttributeValueRepo.Expect(x => x.GetById(cav2_2.Id)).Return(cav2_2);

            var cacheManager = new NopNullCache();

            _storeMappingService = MockRepository.GenerateMock<IStoreMappingService>();

            _eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
            _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));

            _checkoutAttributeService = new CheckoutAttributeService(cacheManager,
                _checkoutAttributeRepo,
                _checkoutAttributeValueRepo,
                _storeMappingService,
                _eventPublisher);

            _checkoutAttributeParser = new CheckoutAttributeParser(_checkoutAttributeService);

            var workingLanguage = new Language();
            _workContext = MockRepository.GenerateMock<IWorkContext>();
            _workContext.Expect(x => x.WorkingLanguage).Return(workingLanguage);
            _currencyService = MockRepository.GenerateMock<ICurrencyService>();
            _taxService = MockRepository.GenerateMock<ITaxService>();
            _priceFormatter = MockRepository.GenerateMock<IPriceFormatter>();
            _downloadService = MockRepository.GenerateMock<IDownloadService>();
            _webHelper = MockRepository.GenerateMock<IWebHelper>();

            _checkoutAttributeFormatter = new CheckoutAttributeFormatter(_workContext,
                _checkoutAttributeService,
                _checkoutAttributeParser,
                _currencyService,
                _taxService,
                _priceFormatter,
                _downloadService,
                _webHelper);
        }