public async Task Handle_ShouldEditCalendarEventDataInDatabase()
        {
            var calendarEvent = new CalendarEvent(
                "Music fetival",
                DateTimeOffset.Now.ToUnixTimeSeconds(),
                "Oosterpark, Amsterdam ",
                "Rafael Caviquioli"
                );

            calendarEvent.AddMember("Aleida");
            calendarEvent.AddMember("Vans Martin");
            _context.Add(calendarEvent);
            await _context.SaveChangesAsync();

            _context.DetachAllEntities();

            var command = new EditCalendarEventCommand()
            {
                Id             = calendarEvent.Id,
                Name           = "Football Challenge",
                Time           = DateTimeOffset.Now.AddDays(10).ToUnixTimeSeconds(),
                Location       = "Brussels, Belgian",
                EventOrganizer = "Elisabeth",
                Members        = new string[] { "Gabriel", "Anna", "Aleida", "Felipe" }
            };
            var handler = new EditCalendarEventCommandHandler(_calendarEventRepository);
            await handler.Handle(command, CancellationToken.None);

            var updatedCalendarEvent = await _context.CalendarEvents
                                       .Include(ce => ce.Members)
                                       .FirstOrDefaultAsync(ce => ce.Id == calendarEvent.Id);

            updatedCalendarEvent.Name.Should().Be(command.Name);
            updatedCalendarEvent.Location.Should().Be(command.Location);
            updatedCalendarEvent.Time.Should().Be(command.Time);
            updatedCalendarEvent.Organizer.Should().Be(command.EventOrganizer);
            updatedCalendarEvent.Members.Should().HaveCount(4);

            var members = updatedCalendarEvent.Members
                          .Select(m => m.Name)
                          .ToList();

            members.Should().Contain("Gabriel");
            members.Should().Contain("Anna");
            members.Should().Contain("Aleida");
            members.Should().Contain("Felipe");
            members.Should().NotContain("Vans Martin");
        }
Exemplo n.º 2
0
        public async Task Handle_RemoveCalendarEvent_WhenItExists()
        {
            var calendarEvent = new CalendarEvent(
                "Music fetival",
                DateTimeOffset.Now.ToUnixTimeSeconds(),
                "Oosterpark, Amsterdam ",
                "Rafael Caviquioli"
                );

            calendarEvent.AddMember("Aleida");
            _context.Add(calendarEvent);
            await _context.SaveChangesAsync();

            _context.DetachAllEntities();

            var command = new RemoveCalendarEventCommand(calendarEvent.Id);
            var handler = new RemoveCalendarEventCommandHandler(_calendarEventRepository);
            await handler.Handle(command, CancellationToken.None);

            var calendarEventExpected = await _context.CalendarEvents
                                        .FirstOrDefaultAsync(ce => ce.Id == calendarEvent.Id);

            calendarEventExpected
            .Should().BeNull("Because calendar event was removed from database");
        }
Exemplo n.º 3
0
        public async Task <string> Handle(AddNewCalendarEventCommand command, CancellationToken cancellationToken)
        {
            var calendarEvent = new CalendarEvent(
                command.Name,
                command.Time,
                command.Location,
                command.EventOrganizer
                );

            foreach (var memberName in command.Members)
            {
                calendarEvent.AddMember(memberName);
            }

            await _calendarEventRepository.Insert(calendarEvent);

            return(calendarEvent.Id);
        }
Exemplo n.º 4
0
        public void EventCharactericChangeTest()
        {
            DateTime      tempTime = DateTime.Now;
            CalendarEvent n        = new CalendarEvent(EventType.Другое, tempTime, tempTime.AddHours(12), EventPlace.Security, 1);

            User tempUser = new User("Petrov", (Post)2, (Department)2);

            n.AddMember(tempUser);

            int temp = n.Change(tempUser, "priority", 3);

            Assert.AreEqual(-1, temp);

            tempUser = new User("Pertov", (Post)0, Department.Research);
            temp     = n.Change(tempUser, "PriOrity", "strg");
            Assert.AreEqual(0, temp);

            temp = n.Change(tempUser, "Description", "dadada");
            Assert.AreEqual(1, temp);
            Assert.AreEqual("dadada", n.Description);
        }