Example #1
0
        public void TestFixtureSetUp()
        {
            //Use In Memory database, open session and Build Schema inside In Memory database
            _dataSession = new DataSession(SQLiteConfiguration.Standard.InMemory());
            _session     = _dataSession.SessionFactory.OpenSession();
            BuildSchema(_session, _dataSession.Configuration);

            //create user
            var plantRepository = new GenericRepository <User>(_session);

            _user = DataGenerator.GetUser();
            _user = plantRepository.SaveOrUpdate(_user);

            //create customer
            var customer = DataGenerator.GetCustomer(_user);

            customer = new GenericRepository <Company>(_session).SaveOrUpdate(customer);

            //Create project under customer
            _project = DataGenerator.GetProject(_user, customer);
            _project = new GenericRepository <Project>(_session).SaveOrUpdate(_project);

            //add project to user
            _user.Projects.Add(_project);
            _user = plantRepository.SaveOrUpdate(_user);

            //create task
            var taskRepository = new TaskRepository(_session);

            _task = taskRepository.SaveOrUpdate(DataGenerator.GetTask(_project, _user));

            //create timeEntryType
            var timeEntryTypeRepository = new TimeEntryTypeRepository(_session);

            _timeEntryType = timeEntryTypeRepository.SaveOrUpdate(DataGenerator.GetTimeEntryType(customer));
        }
            public void GetDateCountByForecastType_CanExtract()
            {
                // Arrange
                var user             = new GenericRepository <User>(Session).SaveOrUpdate(DataGenerator.GetUser());
                var client           = new GenericRepository <Company>(Session).SaveOrUpdate(DataGenerator.GetCustomer(user));
                var project          = new GenericRepository <Project>(Session).SaveOrUpdate(DataGenerator.GetProject(user, client));
                var forecastType     = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Client", "", true, false));
                var forecastTypeRepo = new ForecastTypeRepository(Session);

                forecastTypeRepo.SaveOrUpdate(forecastType);
                var clientForecastTypeId = forecastType.Id;

                var month = new ForecastMonth(1, 2013, 3, user, user);
                var repo  = new ForecastRepository(Session);

                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 1), forecastType, project, 3);
                forecastType = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Vacation", "", false, false));
                forecastTypeRepo.SaveOrUpdate(forecastType);
                var vacationForecastTypeId = forecastType.Id;

                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 2), forecastType, null, 0);
                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 3), forecastType, null, 0);

                var monthRepo = new ForecastMonthRepository(Session);

                monthRepo.SaveOrUpdate(month);

                // Act
                var clientForecastCount   = repo.GetForecastCountByForecastType(1, clientForecastTypeId, DateSpan.YearDateSpan(2013));
                var vacationForecastcount = repo.GetForecastCountByForecastType(1, vacationForecastTypeId, DateSpan.YearDateSpan(2013));

                // Assert
                Assert.That(clientForecastCount, Is.EqualTo(1));
                Assert.That(vacationForecastcount, Is.EqualTo(2));
            }
            public void GetRestOfYear_CanExtract()
            {
                // Arrange
                var user = new GenericRepository <User>(Session).SaveOrUpdate(DataGenerator.GetUser());

                var client = DataGenerator.GetCustomer(user);

                client.Internal = true;
                client          = new GenericRepository <Company>(Session).SaveOrUpdate(client);

                var project             = new GenericRepository <Project>(Session).SaveOrUpdate(DataGenerator.GetProject(user, client));
                var forecastType        = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Client", "", true, true));
                var illnessForecastType = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Illness", "", false, true)
                {
                    StatisticsInclusion = false
                });
                var forecastTypeRepo = new ForecastTypeRepository(Session);

                forecastTypeRepo.SaveOrUpdate(forecastType);

                var repo  = new ForecastRepository(Session);
                var month = new ForecastMonth(1, 2013, 3, user, user);

                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 1), forecastType, project, 7.5m, 1);
                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 2), forecastType, project, 6, 1);
                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 3), forecastType, project, 5, 1);
                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 4), illnessForecastType, null, 0, 7.5m);

                var monthRepo = new ForecastMonthRepository(Session);

                monthRepo.SaveOrUpdate(month);

                // Act
                var all           = repo.GetHourSumByCriteria(1, true, DateSpan.YearDateSpan(2013));
                var allExcluded   = repo.GetHourSumByCriteria(1, false, DateSpan.YearDateSpan(2013));
                var twoByDateSpan = repo.GetHourSumByCriteria(1, true, new DateSpan {
                    From = new DateTime(2013, 1, 1), To = new DateTime(2013, 1, 2)
                });

                // Assert
                Assert.That(all, Is.EqualTo(21.5m)); // 7.5 + 6 + 5 + 1 + 1 + 1 (projecthours and dedicated hours (1's))
                Assert.That(allExcluded, Is.EqualTo(0));
                Assert.That(twoByDateSpan, Is.EqualTo(15.5m));
            }