Ejemplo n.º 1
0
        public async Task ReturnErrorObject_GivenNoRunningGameIsFound()
        {
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "SomeValueHere"),
                new Claim(ClaimTypes.Name, "*****@*****.**")
                // other required and custom claims
            }, "BasicAuth"));
            var mockPhases  = new List <Phase>().AsQueryable().BuildMockDbSet();
            var dataContext = new Mock <DataContext>();

            dataContext.SetupGet(x => x.Phases).Returns(mockPhases.Object);
            var requestContext       = new RequestContext();
            var gameApiServiceLogger = GetMockLogger <GameApiService>().Object;
            var gameApiService       = new Mock <GameApiService>(dataContext.Object, gameApiServiceLogger, requestContext)
            {
                CallBase = true
            }.Object;
            var requestLoggingService = new RequestLoggingService(requestContext, dataContext.Object);
            var logger        = GetMockLogger <JoinController>().Object;
            var modController = new JoinController(requestContext, gameApiService, requestLoggingService, logger);

            modController.ControllerContext             = new ControllerContext();
            modController.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };
            var response = await modController.Post();

            response.StatusCode.Should().Be(200);
            var result = (JoinResponse)response.Value;

            result.Err.Should().NotBeNull();
            result.Err.Description.Should().Be("Game is not running");
        }
Ejemplo n.º 2
0
        public JoinControllerShould()
        {
            var dataContext           = new Mock <DataContext>();
            var requestContext        = new RequestContext();
            var gameApiServiceLogger  = new Mock <ILogger <GameApiService> >().Object;
            var gameApiService        = new Mock <GameApiService>(dataContext.Object, gameApiServiceLogger, requestContext);
            var requestLoggingService = new RequestLoggingService(requestContext, dataContext.Object);
            var logger = Mock.Of <ILogger <JoinController> >();

            controller = new JoinController(requestContext, gameApiService.Object, requestLoggingService, logger);
        }
        public async Task Return500_GivenExceptinoOccursInGameApiService()
        {
            var dataContext          = new Mock <DataContext>();
            var requestContext       = new RequestContext();
            var gameApiServiceLogger = GetMockLogger <GameApiService>().Object;
            var gameApiService       = new Mock <GameApiService>(dataContext.Object, gameApiServiceLogger, requestContext);

            gameApiService.Setup(x => x.GetCurrentStatus()).Throws(new ArgumentNullException());
            var requestLoggingService = new RequestLoggingService(requestContext, dataContext.Object);
            var logger        = GetMockLogger <GameStatusController>().Object;
            var modController = new GameStatusController(requestContext, gameApiService.Object, requestLoggingService, logger);
            var response      = await modController.Get();

            response.StatusCode.Should().Be(500);
            var result = (GameStatusResponse)response.Value;

            result.Err.Should().NotBeNull();
            result.Err.Description.Should().Be("Server Failed to fetch Current Gamestatus");
            result.Err.Message.Should().Be("Internal Server Error");
        }
        public async Task ReturnErrorObject_GivenNoRunningGameIsFound()
        {
            var mockPhases  = new List <Phase>().AsQueryable().BuildMockDbSet();
            var dataContext = new Mock <DataContext>();

            dataContext.SetupGet(x => x.Phases).Returns(mockPhases.Object);
            var requestContext       = new RequestContext();
            var gameApiServiceLogger = GetMockLogger <GameApiService>().Object;
            var gameApiService       = new Mock <GameApiService>(dataContext.Object, gameApiServiceLogger, requestContext)
            {
                CallBase = true
            }.Object;
            var requestLoggingService = new RequestLoggingService(requestContext, dataContext.Object);
            var logger        = GetMockLogger <GameStatusController>().Object;
            var modController = new GameStatusController(requestContext, gameApiService, requestLoggingService, logger);
            var response      = await modController.Get();

            response.StatusCode.Should().Be(200);
            var result = (GameStatusResponse)response.Value;

            result.Err.Should().NotBeNull();
            result.Err.Description.Should().Be("Game is not running");
        }