public async Task Post_WithoutException_ReturnNotFound()
        {
            var mocks = GetMocks();

            mocks.Service.Setup(s => s.Authenticate(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(default(Account));

            AuthenticateController controller = GetController(mocks);
            var result = await controller.Post(new LoginViewModel()
            {
                Password = "******",
                Username = "******"
            });

            Assert.Equal((int)HttpStatusCode.NotFound, GetStatusCode(result));
        }
        public async Task Post_WithException_ReturnBadRequest()
        {
            var mocks = GetMocks();

            mocks.Service.Setup(s => s.Authenticate(It.IsAny <string>(), It.IsAny <string>())).ThrowsAsync(new Exception("error"));

            AuthenticateController controller = GetController(mocks);
            var result = await controller.Post(new LoginViewModel()
            {
                Password = "******",
                Username = "******"
            });

            Assert.Equal((int)HttpStatusCode.BadRequest, GetStatusCode(result));
        }
Ejemplo n.º 3
0
        public void Post_Logginn_NOT_Found_I_DB()
        {
            LogInn bruker = new LogInn();

            bruker.Brukernavn = "*****@*****.**";
            bruker.Passord    = "passord123";

            var commandBus = new Mock <IBrukerLogikk>();

            commandBus.Setup(c => c.BrukerIdb(bruker)).Returns(true);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();

            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                                                  new HttpRouteValueDictionary {
                { "controller", "Authenticate" }
            });
            var controller = new AuthenticateController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Authenticate/")
                {
                    Properties =
                    {
                        { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                        { HttpPropertyKeys.HttpRouteDataKey,     httpRouteData     }
                    }
                }
            };
            LogInn nyBruker = new LogInn();

            nyBruker.Brukernavn = "*****@*****.**";
            nyBruker.Passord    = "yolo1231";
            var response = controller.Post(nyBruker);

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            // Act
        }
Ejemplo n.º 4
0
        public void Post_Logginn_Ok()
        {
            LogInn nyBruker = new LogInn()
            {
                Brukernavn = "*****@*****.**",
                Passord    = "password"
            };
            var commandBus = new Mock <IBrukerLogikk>();

            commandBus.Setup(c => c.BrukerIdb(It.IsAny <LogInn>())).Returns(true);

            var httpConfiguration = new HttpConfiguration();

            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                                                  new HttpRouteValueDictionary {
                { "controller", "Authenticate" }
            });
            var controller = new AuthenticateController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Authenticate/")
                {
                    Properties =
                    {
                        { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                        { HttpPropertyKeys.HttpRouteDataKey,     httpRouteData     }
                    }
                }
            };
            // Act
            var response = controller.Post(nyBruker);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            // Assert.AreEqual(string.Format("http://localhost/api/Authenticate/", nyBruker.Brukernavn), response.Headers.Location.ToString());
        }
Ejemplo n.º 5
0
        public void Post_Logginn_Not_Found()
        {
            var commandBus = new Mock <IBrukerLogikk>();

            commandBus.Setup(c => c.BrukerIdb(It.IsAny <LogInn>())).Returns(true);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();

            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                                                  new HttpRouteValueDictionary {
                { "controller", "Authenticate" }
            });
            var controller = new AuthenticateController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Authenticate/")
                {
                    Properties =
                    {
                        { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                        { HttpPropertyKeys.HttpRouteDataKey,     httpRouteData     }
                    }
                }
            };
            LogInn nyBruker = new LogInn();

            nyBruker.Brukernavn = "";
            // The ASP.NET pipeline doesn't run, so validation don't run.
            controller.ModelState.AddModelError("Email", "mock error message");
            var response = controller.Post(nyBruker);

            // Assert
            commandBus.Verify(e => e.BrukerIdb(nyBruker), Times.Never);
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            // Act
        }