Example #1
0
        public void Handle_ShouldCreateEvent()
        {
            var name    = "Name";
            var dates   = Enumerable.Empty <LocalDate>();
            var command = new CreateEventCommand(name, dates);

            var result = _handler.Handle(command, new CancellationToken());

            _eventRepository.Received(1).Add(Arg.Is <EventEntity>(e => e.Name == name));
            _unitOfWork.Received(1).Save(Arg.Any <CancellationToken>());
        }
        public async Task CreateEventCommand_returns_eventdetailmodel()
        {
            var handler = new CreateEventCommandHandler(_context);

            var newEventId = await handler.Handle(new CreateEventCommand
            {
                Name          = "TestEvent3",
                StartDateTime = DateTime.Now,
                EndDateTime   = DateTime.Now.AddDays(1)
            }, CancellationToken.None);

            var result = await _context.Events.FindAsync(newEventId);

            result.Id.Should().Be(newEventId);
            result.Name.Should().Be("TestEvent3");
        }
Example #3
0
        public async Task Handle_Given_Minimum_Valid_Values_Creates_Event()
        {
            // Arrange
            var validTitle        = "Event Created from Unit Tests.";
            var validDescription  = "This event was created from a Unit Test.";
            var validStartDate    = new DateTime(2020, 3, 1);
            var validEndDate      = new DateTime(2020, 3, 2);
            var validRegStartDate = new DateTime(2020, 2, 1);
            var validRegEndDate   = new DateTime(2020, 2, 2);
            var validMaxRegs      = 10;
            var validEventTypeId  = 1;
            var command           = new CreateEventCommand
            {
                Title        = validTitle,
                Description  = validDescription,
                StartDate    = validStartDate,
                EndDate      = validEndDate,
                RegStartDate = validRegStartDate,
                RegEndDate   = validRegEndDate,
                MaxRegsCount = validMaxRegs,
                EventTypeId  = validEventTypeId
            };

            // Act
            var result = await _sut.Handle(command, CancellationToken.None);

            Event e = _context.Events.FirstOrDefault(x => x.Title == validTitle);

            // Assert
            Assert.NotNull(e);
            Assert.Equal(e.Title, validTitle);
            Assert.Equal(e.Description, validDescription);
            Assert.Equal(e.Dates.StartDate, validStartDate);
            Assert.Equal(e.Dates.EndDate, validEndDate);
            Assert.Equal(e.Dates.RegistrationStartDate, validRegStartDate);
            Assert.Equal(e.Dates.RegistrationEndDate, validRegEndDate);
            Assert.Equal((int)e.Rules.MaxRegistrations, validMaxRegs);
            Assert.Equal(e.EventTypeId, validEventTypeId);
        }