Click here to Skip to main content
15,893,814 members
Articles / Hosted Services / Azure

YouConf - Your Live Online Conferencing Tool

Rate me:
Please Sign up or sign in to vote.
4.96/5 (41 votes)
17 Nov 2013CPOL167 min read 259.6K   660   70  
A site for managing and delivering virtual conferences - complete with embedded live streaming and chat. Showcasing the best Azure has to offer!
using FluentAssertions;
using FluentAssertions.Mvc;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using YouConf.Migrations;
using System.Collections.Generic;
using YouConf.Controllers;
using System.Web.Mvc;
using System.Data.Entity.Migrations;
using YouConf.Tests.Integration.Extensions;
using Moq;
using System.Web;
using System.Security.Principal;
using System.Web.Routing;
using SolrNet;
using YouConf.Common.Data.Entities;

namespace YouConf.Tests.Integration
{
    [TestClass]
    public class ConferenceControllerTests : TestBase
    {
        
        [TestMethod]
        public void All_Should_ReturnOnlyPublicConferences()
        {
            //Three public conferences, one private
            _context.Conferences.Add(new Conference() { HashTag = "test", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = true });
            _context.Conferences.Add(new Conference() { HashTag = "test", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = true });
            _context.Conferences.Add(new Conference() { HashTag = "test", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = true });
            _context.Conferences.Add(new Conference() { HashTag = "test", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = false });
            _context.SaveChangesWithErrors();


            var conferenceController = new ConferenceController(_context);

            var result = conferenceController.All()
                .As<ViewResult>();

            result.Model
                .As<IEnumerable<Conference>>()
                .Should().HaveCount(3);
        }

        [TestMethod]
        public void Details_WithInvalidHashTag_Should_ReturnHttpNotFoundResult()
        {
            var conferenceController = new ConferenceController(_context);

            var result = conferenceController.Details("thisisinvalid")
                .As<HttpNotFoundResult>();
        }


        [TestMethod]
        public void Details_WithValidHashTag_Should_ReturnCorrectConference()
        {
            var stubConference = new Conference() { HashTag = "abcde", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = true };
            _context.Conferences.Add(stubConference);
            _context.Conferences.Add(new Conference() { HashTag = "test", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = false });
            _context.SaveChangesWithErrors(); ;

            var conferenceController = new ConferenceController(_context);
            conferenceController.ControllerContext = TestHelper.MockContext(conferenceController, "TestUser");

            var result = conferenceController.Details("abcde")
                .As<ViewResult>();

            result.Model
                .As<Conference>()
                .Should()
                .Be(stubConference);
        }

        [TestMethod]
        public void Create_WithAlreadyUsedHashTag_Should_ReturnViewAndAddModelError()
        {
            _context.Conferences.Add(new Conference() { HashTag = "abcde", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = false });
            _context.SaveChangesWithErrors();

            var conferenceController = new ConferenceController(_context);

            var newConference = new Conference() { HashTag = "abcde" };
            var result = conferenceController.Create(newConference)
                .As<ViewResult>();

            result.ViewData.ModelState["HashTag"]
                .Errors
                .Count
                .Should()
                .Be(1);
        }       
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
New Zealand New Zealand
I'm a software developer based in the beautiful city of Wellington, New Zealand. I love experimenting with new .Net technologies as they arrive, and these days there seems to be a lot of choice as there are so many new features in the framework! My current interests are Azure, ASP.Net MVC, SignalR, Knockout, AngularJS, and responsive design (inc. using Bootstrap, Foundation, Skeleton). These change fairly often as I tinker with various new technologies...

Comments and Discussions