Пример #1
0
            public void UpdateAndInsertItems()
            {
                var list           = new List <TimeEntry>();
                var timeEntryToAdd = new TimeEntry()
                {
                    Id       = ObjectId.GenerateNewId(),
                    Date     = DateTime.Now,
                    Project  = "project 2",
                    Quantity = 8
                };

                timeEntryToUpdate.Quantity = 8;
                list.Add(timeEntryToUpdate);
                list.Add(timeEntryToAdd);

                var command        = new CreateOrUpdateTimeSheet(list, "FakeUser");
                var commandHandler = new CreateOrUpdateTimeSheetHandler(mockSession);

                commandHandler.Execute(command);

                Assert.AreEqual(2, ((MockSession)mockSession).collection.Count);
                Assert.AreEqual(8, mockSession.GetQueryable <TimeEntry>().Single(c => c.Id == timeEntryToUpdate.Id).Quantity);
                Assert.AreEqual(8, mockSession.GetQueryable <TimeEntry>().Single(c => c.Id == timeEntryToAdd.Id).Quantity);
                Assert.AreEqual("project 2", mockSession.GetQueryable <TimeEntry>().Single(c => c.Id == timeEntryToAdd.Id).Project);

                Assert.AreEqual(timeEntryToUpdate.Date, mockSession.GetQueryable <TimeEntry>().Single(c => c.Id == timeEntryToUpdate.Id).Date);
                Assert.AreEqual(timeEntryToAdd.Date, mockSession.GetQueryable <TimeEntry>().Single(c => c.Id == timeEntryToAdd.Id).Date);
            }
Пример #2
0
            public void UpdateItemWithQuantityNull()
            {
                var list = new List <TimeEntry>();

                timeEntryToUpdate.Quantity = null;
                list.Add(timeEntryToUpdate);

                var command        = new CreateOrUpdateTimeSheet(list, "FakeUser");
                var commandHandler = new CreateOrUpdateTimeSheetHandler(mockSession);

                commandHandler.Execute(command);

                Assert.AreEqual(1, ((MockSession)mockSession).collection.Count);
                Assert.AreEqual(null, mockSession.GetQueryable <TimeEntry>().Single(c => c.Id == timeEntryToUpdate.Id).Quantity);
            }
Пример #3
0
        public ActionResult Index(TimeSheet timeSheet)
        {
            if (ModelState.IsValid)
            {
                var command = new CreateOrUpdateTimeSheet(timeSheet.TimeEntries, MvcApplication.GetCurrentUser);
                var createOrUpdateTSResult = commandBus.Submit <CreateOrUpdateTimeSheet>(command);
                var assignProjectResult    = commandBus.Submit <AssignProject>(new AssignProject(MvcApplication.GetCurrentUser, timeSheet.SelectedProject));

                if (assignProjectResult.Success && createOrUpdateTSResult.Success)
                {
                    this.ShowMessage(MessageType.Success, "The information was succesfully saved!", true);
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                this.ShowMessage(MessageType.Error, "There a error in the time sheet.", true);
                return(View(timeSheet));
            }
        }