public void GetEventById_ShouldReturnSingleEventWithTheGivenId()
        {
            var context = new EventuresDbContext(this.Options);

            var events = new List <Event>
            {
                new Event {
                    Id = "1", Name = "Event1"
                },
                new Event {
                    Id = "2", Name = "Event2"
                },
                new Event {
                    Id = "3", Name = "Event3"
                },
            };

            context.Events.AddRange(events);
            context.SaveChanges();

            var service = new EventsService(context);

            var resultEvent = service.GetEventById("1");

            Assert.Equal(events[0], resultEvent);
            Assert.Equal(events[0].Name, resultEvent.Name);
        }
Beispiel #2
0
        public void GetEventById_ThrowsEntityNotFound_WhenEventDoesNotExist()
        {
            var nonExistingId = Guid.NewGuid().ToString();
            var eventService  = new EventsService(eventRepoMock.Object);

            Assert.ThrowsException <EntityNotFoundException>(() =>
            {
                eventService.GetEventById(nonExistingId);
            });
        }
Beispiel #3
0
        public void GetEventById_ThrowsException_WhenEventIdHasInvalidValue()
        {
            var eventService = new EventsService(eventRepoMock.Object);

            var badId = "asdjlkasdklas sakld askld";

            Assert.ThrowsException <Exception>(() =>
            {
                eventService.GetEventById(badId);
            });
        }
        public void GetEventById_WithInexistingIdShouldReturnNull(string id)
        {
            var context = new EventuresDbContext(this.Options);

            var @event = new Event {
                Id = "1"
            };

            context.Events.Add(@event);
            context.SaveChanges();

            var service = new EventsService(context);

            var resultEvent = service.GetEventById(id);

            Assert.Null(resultEvent);
        }
Beispiel #5
0
        public void GetEventById_Returns_EventWhenExists()
        {
            Exception throwException = null;
            var       eventService   = new EventsService(eventRepoMock.Object);
            Event     eventt         = null;

            try
            {
                eventt = eventService.GetEventById(existingEventId.ToString());
            }
            catch (Exception e)
            {
                throwException = e;
            }

            Assert.IsNull(throwException, $"Exception was thrown");
            Assert.IsNotNull(eventt);
        }