public void Contains_Errors_When_Use_Case_Fails() { // arrange var presenter = new LoginPresenter(); // act presenter.Handle(new LoginResponse(new[] { new Error("", "Invalid username/password") })); // assert var data = JsonConvert.DeserializeObject <IEnumerable <Error> >(presenter.ContentResult.Content); Assert.Equal((int)HttpStatusCode.Unauthorized, presenter.ContentResult.StatusCode); Assert.Equal("Invalid username/password", data.First().Description); }
public void Contains_Token_When_Use_Case_Succeeds() { // arrange const string authToken = "777888AAABBB"; var presenter = new LoginPresenter(); // act presenter.Handle(new LoginResponse(new Token("1", authToken, 0), true)); // assert dynamic data = JsonConvert.DeserializeObject(presenter.ContentResult.Content); Assert.Equal(authToken, data.authtoken.Value); }
public void Handle_GivenSuccessfulUseCaseResponse_SetsOKHttpStatusCode() { // arrange var presenter = new LoginPresenter(_mapper); // act presenter.Handle(new LoginResponse(new AccessToken("", 0), "", true)); // assert Assert.NotNull(presenter.Response); Assert.NotNull(presenter.Response.Response); Assert.True(presenter.Response.Response.Success); Assert.False(presenter.Response.Response.Errors.Any()); }
public void Handle_GivenSuccessfulUseCaseResponse_SetsAccessToken() { // arrange const string token = "777888AAABBB"; var presenter = new LoginPresenter(); // act presenter.Handle(new LoginResponse(new AccessToken(token, 0), "", true)); // assert dynamic data = JsonConvert.DeserializeObject(presenter.ContentResult.Content); Assert.Equal(token, data.accessToken.token.Value); }
public void Handle_GivenFailedUseCaseResponse_SetsErrors() { // arrange var presenter = new LoginPresenter(); // act presenter.Handle(new LoginResponse(new List <Error> { new Error("", "Invalid username/password") })); // assert var data = JsonConvert.DeserializeObject <List <Error> >(presenter.ContentResult.Content); Assert.Equal((int)HttpStatusCode.Unauthorized, presenter.ContentResult.StatusCode); Assert.Equal("Invalid username/password", data.First().Description); }
public void Handle_GivenSuccessfulUseCaseResponse_SetsAccessToken() { // arrange const string token = "777888AAABBB"; var presenter = new LoginPresenter(_mapper); // act presenter.Handle(new LoginResponse(new AccessToken(token, 0), "", true)); // assert Assert.NotNull(presenter.Response); Assert.NotNull(presenter.Response.Response); Assert.True(presenter.Response.Response.Success); Assert.False(presenter.Response.Response.Errors.Any()); Assert.Equal(token, presenter.Response.AccessToken.Token); }
public void Handle_GivenFailedUseCaseResponse_SetsErrors() { // arrange var presenter = new LoginPresenter(_mapper); // act presenter.Handle(new LoginResponse(new List <Error> { new Error(HttpStatusCode.BadRequest.ToString(), "Invalid username/password") })); // assert Assert.NotNull(presenter.Response); Assert.NotNull(presenter.Response.Response.Errors); Assert.NotEmpty(presenter.Response.Response.Errors); Assert.False(presenter.Response.Response.Success); Assert.NotNull(presenter.Response.Response.Errors); Assert.False(string.IsNullOrEmpty(presenter.Response.Response.Errors.First().Code)); Assert.False(string.IsNullOrEmpty(presenter.Response.Response.Errors.First().Description)); Assert.Equal(HttpStatusCode.BadRequest.ToString(), presenter.Response.Response.Errors.First().Code); Assert.Equal("Invalid username/password", presenter.Response.Response.Errors.First().Description); }
public void Handle_GivenFailedUseCaseResponse_SetsErrors() { // arrange var presenter = new LoginPresenter(); // act presenter.Handle(new LoginResponse(new List <Error> { new Error(HttpStatusCode.BadRequest.ToString(), "Invalid username/password") })); // assert Models.Response.LoginResponse response = JsonSerializer.DeSerializeObject <Models.Response.LoginResponse>(presenter.ContentResult.Content); Assert.Equal((int)HttpStatusCode.Unauthorized, presenter.ContentResult.StatusCode); Assert.NotNull(response); Assert.NotNull(response.Errors); Assert.NotEmpty(response.Errors); Assert.False(response.Success); Assert.NotNull(response.Errors); Assert.False(string.IsNullOrEmpty(response.Errors.First().Code)); Assert.False(string.IsNullOrEmpty(response.Errors.First().Description)); Assert.Equal(HttpStatusCode.BadRequest.ToString(), response.Errors.First().Code); Assert.Equal("Invalid username/password", response.Errors.First().Description); }