public async Task GetAttendeeSuccessful()
        {
            var username                = "******";
            var testAttendee            = GetTestAttendee(username);
            var attendeesRepositoryStub = new Mock <IAttendeesRepository>();

            attendeesRepositoryStub.Setup(ar => ar.GetByUsernameAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(testAttendee);

            var sessionsRepositoryStub    = new Mock <ISessionsRepository>();
            var conferencesRepositoryStub = new Mock <IConferencesRepository>();

            var cacheStub = new Mock <IDistributedCache>();

            cacheStub.Setup(c => c.GetAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync((byte[])null);

            var controller = new AttendeesController(attendeesRepositoryStub.Object, sessionsRepositoryStub.Object, conferencesRepositoryStub.Object);

            var result        = (await controller.GetByUsername(username)).Value;
            var expectedValue = GetTestAttendeeResponse(username);

            Assert.Equal(expectedValue.ID, result.ID);
            Assert.Equal(expectedValue.FirstName, result.FirstName);
            Assert.Equal(expectedValue.LastName, result.LastName);
            Assert.Equal(expectedValue.Sessions.FirstOrDefault()?.ID, result.Sessions.FirstOrDefault()?.ID);
            Assert.Equal(expectedValue.Sessions.FirstOrDefault()?.Title, result.Sessions.FirstOrDefault()?.Title);
            Assert.Equal(expectedValue.Conferences.FirstOrDefault()?.ID, result.Conferences.FirstOrDefault()?.ID);
            Assert.Equal(expectedValue.Conferences.FirstOrDefault()?.Name, result.Conferences.FirstOrDefault()?.Name);
        }
    public virtual async Task AttendeesController_GetSessions()
    => await ExecuteWithStrategyInTransactionAsync(
        async context =>
    {
        var controller = new AttendeesController(context);

        var sessions = await controller.GetSessions("Princess");

        Assert.Equal(21, sessions.Count);
        Assert.All(sessions, s => Assert.NotEmpty(s.Abstract));
        Assert.All(sessions, s => Assert.NotEmpty(s.Speakers));
        Assert.All(sessions, s => Assert.NotNull(s.Track));
    });
        public virtual async Task AttendeesController_Post_with_new_attendee()
        {
            await ExecuteWithStrategyInTransactionAsync(
                async context =>
            {
                var controller = new AttendeesController(context);

                var result = await controller.Post(
                    new Attendee {
                    EmailAddress = "*****@*****.**", FirstName = "", LastName = "Discord", UserName = "******"
                });

                Assert.NotEqual(default, result.Id);
Example #4
0
        public async Task Edit_ReturnsHttpNotFoundWhenAttendeeIdNotFound()
        {
            //Arrange
            int AttendeeID = 4;
            var dbContext  = await GetDatabaseContext();

            var attendeesController = new AttendeesController(dbContext);

            //Act
            var result = await attendeesController.Edit(AttendeeID);

            //Assert
            Assert.IsType <NotFoundResult>(result);
        }
Example #5
0
        public async Task Index_ReturnsAViewResult_WithAListOfAttendees()
        {
            //Arrange
            var dbContext = await GetDatabaseContext();

            var attendeesController = new AttendeesController(dbContext);
            //Act
            var result = await attendeesController.Index("", "", "", null);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <Attendee> >(
                viewResult.ViewData.Model);

            Assert.Equal(2, model.Count());
        }
    public virtual async Task AttendeesController_Get()
    => await ExecuteWithStrategyInTransactionAsync(
        async context =>
    {
        var controller = new AttendeesController(context);

        var attendee = await controller.Get("RainbowDash");

        Assert.Equal("Rainbow", attendee.FirstName);
        Assert.Equal("Dash", attendee.LastName);
        Assert.Equal("RainbowDash", attendee.UserName);
        Assert.Equal("*****@*****.**", attendee.EmailAddress);

        var sessions = attendee.Sessions;

        Assert.Equal(21, sessions.Count);
        Assert.All(sessions, s => Assert.NotEmpty(s.Title));
    });
Example #7
0
        public async Task Details_ReturnsViewResultWithAttendeeModel()
        {
            //Arrange
            var dbContext = await GetDatabaseContext();

            var attendeesController = new AttendeesController(dbContext);

            //Act
            var result = await attendeesController.Details(11);

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsType <Attendee>(
                viewResult.ViewData.Model);

            Assert.Equal(11, model.AttendeeID);
            Assert.Equal("Test", model.Name);
            Assert.Equal("032492809", model.Phone);
            Assert.Equal("*****@*****.**", model.Email);
            Assert.Equal(11, model.EventID);
        }