Example #1
0
        public void WhenUserLogsInMultipleTimes_ThenEmployeeTimeClockRecordIsReused()
        {
            Mock <IMessageBus> mockEvents  = new Mock <IMessageBus>();
            BBQRMSEntities     dataService = new BBQRMSEntities(_serviceAddress);
            var newEmp = PrepareEmployee.With(firstName: "George", lastName: "Harrison").HiredOn(Time.Now.Date);

            dataService.AddToEmployees(newEmp);
            var resp = dataService.SaveChanges(SaveChangesOptions.Batch);

            var startTime = Time.UtcNow;

            LoginViewModel toTest = new LoginViewModel(dataService, mockEvents.Object);

            //login once
            toTest.PrepareTimeClock(newEmp);

            Time.SkipForwardBy(TimeSpan.FromMinutes(5));
            var afterFirstLoginTime = Time.UtcNow;

            //login again
            toTest.PrepareTimeClock(newEmp);

            Time.SkipForwardBy(TimeSpan.FromMinutes(5));
            //login a third time
            toTest.PrepareTimeClock(newEmp);

            //We should still only have one TimeClock record.
            var openClocks = dataService.EmployeeTimeClocks.Where(tc => tc.EmployeeId == newEmp.Id).ToList();

            Assert.AreEqual(1, openClocks.Count);
            Assert.IsNull(openClocks[0].ClockOutTimeUTC);
            Assert.IsTrue(openClocks[0].ClockInTimeUTC >= startTime);
            Assert.IsTrue(openClocks[0].ClockInTimeUTC < afterFirstLoginTime);
        }
        public static void BeforeAllTests(TestContext testContext)
        {
            ServerTimeProvider.Current = Time;
            ClientTimeProvider.Current = Time;
            // start the data service
            _serviceAddress = new Uri("http://localhost:80/Temporary_Listen_Addresses/BBQRMSTestingGivenManagerIsViewingChooseReportScreen/");
            Host.Open(_serviceAddress);
            _dataService = new BBQRMSEntities(_serviceAddress);

            _mockMessageBus = new Mock <IMessageBus>();

            _mockSecurityContext = new Mock <ISecurityContext>();
            var reportingRole = PrepareRole.Named("Reporting").WithPrivelege(Privileges.RunReports);
            var mockEmployee  = PrepareEmployee.With(firstName: "Bob", lastName: "Marley").AndRole(reportingRole);

            _mockSecurityContext.SetupGet(s => s.CurrentUser).Returns(mockEmployee);

            _chooseReportViewModel = new ChooseReportViewModel(_dataService, _mockMessageBus.Object, Time);
        }
        public void BeforeEachTest()
        {
            _mockMessageBus = new Mock <IMessageBus>();
            //Create new employee to use for this test run.
            var employee = PrepareEmployee.With().HiredOn(DateTime.Today);

            _dataService.AddToEmployees(employee);
            var resp = _dataService.SaveChanges(SaveChangesOptions.Batch);

            Assert.IsTrue(resp.BatchStatusCode >= 200 && resp.BatchStatusCode < 300);

            var login = new LoginViewModel(_dataService, _mockMessageBus.Object);

            login.PrepareTimeClock(employee);

            _mockSecurityContext = new Mock <ISecurityContext>();
            //Make this the logged-in employee.
            _mockSecurityContext.SetupGet(s => s.CurrentUser).Returns(employee);
        }
        public static void BeforeAllTests(TestContext testContext)
        {
            ServerTimeProvider.Current = Time;
            ClientTimeProvider.Current = Time;
            // start the data service
            _serviceAddress = new Uri("http://localhost:80/Temporary_Listen_Addresses/BBQRMSTestingGivenPostLoginView/");
            Host.Open(_serviceAddress);
            _dataService = new BBQRMSEntities(_serviceAddress);

            var emp = PrepareEmployee.With(firstName: "George", lastName: "Jones");

            _dataService.AddToEmployees(emp);
            var user = new ApplicationUser {
                IdPart = "2", PersonalPart = "22"
            };

            _dataService.AddToApplicationUsers(user);
            _dataService.AddLink(emp, "ApplicationUsers", user);
            _dataService.SaveChanges(SaveChangesOptions.Batch);
        }
Example #5
0
        public void WhenUserLogsInFirstTime_ThenEmployeeTimeClockIsCreated()
        {
            Mock <IMessageBus> mockEvents  = new Mock <IMessageBus>();
            BBQRMSEntities     dataService = new BBQRMSEntities(_serviceAddress);
            var newEmp = PrepareEmployee.With(firstName: "Ringo", lastName: "Starr").HiredOn(Time.Now.Date);

            dataService.AddToEmployees(newEmp);
            var resp = dataService.SaveChanges(SaveChangesOptions.Batch);

            var startTime = Time.UtcNow;

            LoginViewModel toTest = new LoginViewModel(dataService, mockEvents.Object);

            toTest.PrepareTimeClock(newEmp);

            //We should have a new timeclock record.
            var openClocks = dataService.EmployeeTimeClocks.Where(tc => tc.EmployeeId == newEmp.Id).ToList();

            Assert.AreEqual(1, openClocks.Count);
            Assert.IsNull(openClocks[0].ClockOutTimeUTC);
            Assert.IsTrue(openClocks[0].ClockInTimeUTC >= startTime);
        }
Example #6
0
        public static void BeforeAllTests(TestContext testContext)
        {
            ServerTimeProvider.Current = Time;
            ClientTimeProvider.Current = Time;
            // start the data service
            _serviceAddress = new Uri("http://localhost:80/Temporary_Listen_Addresses/BBQRMSTestingGivenNothing/");
            Host.Open(_serviceAddress);

            var _dataService = new BBQRMSEntities(_serviceAddress);

            _employee = PrepareEmployee.With(firstName: "Paul", lastName: "McCartney");
            _dataService.AddToEmployees(_employee);
            var user = new ApplicationUser {
                IdPart = "1", PersonalPart = "11"
            };

            _dataService.AddToApplicationUsers(user);
            _dataService.AddLink(_employee, "ApplicationUsers", user);
            _dataService.SaveChanges(SaveChangesOptions.Batch);

            Assert.IsTrue(_employee.Id > 0);
        }