public void Setup() { _container = new MocksAndStubsContainer(); _repositoryFactory = _container.RepositoryFactory; _settingsRepository = _container.SettingsRepository; _settingsService = _container.SettingsService; }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _applicationSettings.Installed = false; _settingsService = _container.SettingsService; _userService = _container.UserService; _configReaderWriter = _container.ConfigReaderWriter; _repositoryFactory = _container.RepositoryFactory; _installationService = _container.InstallationService; _databaseTester = _container.DatabaseTester; _installerRepository = _container.InstallerRepository; _installController = new InstallController(_applicationSettings, _configReaderWriter, _installationService, _databaseTester); }
public void setsupporteddatabases_should_convert_repositoryinfo_objects_selectlist() { // Arrange var respositoryFactory = new RepositoryFactoryMock(); List <RepositoryInfo> repositoryInfos = respositoryFactory.ListAll().ToList(); SettingsViewModel model = new SettingsViewModel(); // Act model.SetSupportedDatabases(repositoryInfos); // Assert Assert.That(model.DatabaseTypesAsSelectList.Count, Is.EqualTo(repositoryInfos.Count())); var firstItem = repositoryInfos[0]; Assert.That(model.DatabaseTypesAsSelectList[0].Value, Is.EqualTo(firstItem.Id)); Assert.That(model.DatabaseTypesAsSelectList[0].Text, Is.EqualTo(firstItem.Description)); }
public void CalcCashFlow() { var factory = new RepositoryFactoryMock(); var repo = factory.CreateParticipantRepository(); var bob = new Participant { DisplayName = "Bob", Email = "*****@*****.**" }; var sheryl = new Participant { DisplayName = "Sheryl", Email = "*****@*****.**" }; var dave = new Participant { DisplayName = "Dave", Email = "*****@*****.**" }; repo.AddParticipant(bob); repo.AddParticipant(sheryl); repo.AddParticipant(dave); var manager = new SettlementPlanManager(factory); var nyPlan = manager.CreateSettlementPlan("trip to NY"); nyPlan.AddParticipant(bob.Id); nyPlan.AddParticipant(sheryl.Id); nyPlan.AddParticipant(dave.Id); nyPlan.AddCharge(new Charge { Category = Category.Entertainment, Date = new DateTime(), TotalCharge = 100, DebtByPerson = new List <KeyValuePair <string, double> > { new KeyValuePair <string, double>(bob.Id, 10), new KeyValuePair <string, double>(sheryl.Id, 50), new KeyValuePair <string, double>(dave.Id, 40) }, Payer = bob.Id }); nyPlan.AddCharge(new Charge { Category = Category.Dining, Date = new DateTime(), TotalCharge = 130, DebtByPerson = new List <KeyValuePair <string, double> > { new KeyValuePair <string, double>(bob.Id, 100), new KeyValuePair <string, double>(dave.Id, 30) }, Payer = sheryl.Id }); var result = nyPlan.CalculateDebts(); //bob owes 10 to cheryl Assert.AreEqual(result[0].PersonWhoOwes, bob.Id); Assert.AreEqual(result[0].PersonWhoGetPayed, sheryl.Id); Assert.AreEqual(result[0].DebtAmount, 10.0); //dave owes 70 to cheryl Assert.AreEqual(result[1].PersonWhoOwes, dave.Id); Assert.AreEqual(result[1].PersonWhoGetPayed, sheryl.Id); Assert.AreEqual(result[1].DebtAmount, 70.0); }
public ControllerDataMock() { RepositoryFactory = new RepositoryFactoryMock(); }
/// <summary> /// Creates a new instance of MocksAndStubsContainer. /// </summary> /// <param name="useCacheMock">The 'Roadkill' MemoryCache is used by default, but as this is static it can have problems with /// the test runner unless you clear the Container.MemoryCache on setup each time, but then doing that doesn't give a realistic /// reflection of how the MemoryCache is used inside an ASP.NET environment.</param> public MocksAndStubsContainer(bool useCacheMock = false) { ApplicationSettings = new ApplicationSettings(); ApplicationSettings.Installed = true; ApplicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments"); ConfigReaderWriter = new ConfigReaderWriterStub(); // Cache MemoryCache = useCacheMock ? new CacheMock() : CacheMock.RoadkillCache; ListCache = new ListCache(ApplicationSettings, MemoryCache); SiteCache = new SiteCache(MemoryCache); PageViewModelCache = new PageViewModelCache(ApplicationSettings, MemoryCache); // Repositories SettingsRepository = new SettingsRepositoryMock(); SettingsRepository.SiteSettings = new SiteSettings(); SettingsRepository.SiteSettings.MarkupType = "Creole"; UserRepository = new UserRepositoryMock(); PageRepository = new PageRepositoryMock(); InstallerRepository = new InstallerRepositoryMock(); RepositoryFactory = new RepositoryFactoryMock() { SettingsRepository = SettingsRepository, UserRepository = UserRepository, PageRepository = PageRepository, InstallerRepository = InstallerRepository }; DatabaseTester = new DatabaseTesterMock(); // Plugins PluginFactory = new PluginFactoryMock(); MarkupConverter = new MarkupConverter(ApplicationSettings, SettingsRepository, PageRepository, PluginFactory); // Services // Dependencies for PageService. Be careful to make sure the class using this Container isn't testing the mock. SettingsService = new SettingsService(RepositoryFactory, ApplicationSettings); UserService = new UserServiceMock(ApplicationSettings, UserRepository); UserContext = new UserContext(UserService); SearchService = new SearchServiceMock(ApplicationSettings, SettingsRepository, PageRepository, PluginFactory); SearchService.PageContents = PageRepository.PageContents; SearchService.Pages = PageRepository.Pages; HistoryService = new PageHistoryService(ApplicationSettings, SettingsRepository, PageRepository, UserContext, PageViewModelCache, PluginFactory); FileService = new FileServiceMock(); PageService = new PageService(ApplicationSettings, SettingsRepository, PageRepository, SearchService, HistoryService, UserContext, ListCache, PageViewModelCache, SiteCache, PluginFactory); StructureMapContainer = new Container(x => { x.AddRegistry(new TestsRegistry(this)); }); Locator = new StructureMapServiceLocator(StructureMapContainer, false); InstallationService = new InstallationService((databaseName, connectionString) => { InstallerRepository.DatabaseName = databaseName; InstallerRepository.ConnectionString = connectionString; return(InstallerRepository); }, Locator); // EmailTemplates EmailClient = new EmailClientMock(); }