PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/EndToEnd/RegistrationTests.cs

https://github.com/khalidabuhakmeh/EndToEnd
C# | 68 lines | 60 code | 8 blank | 0 comment | 0 complexity | b4168e23e6e3f3bec2e3738d8c60eef0 MD5 | raw file
  1. using System;
  2. using EndToEnd.Core;
  3. using FluentAssertions;
  4. using ServiceStack.FluentValidation;
  5. using ServiceStack.ServiceClient.Web;
  6. using ServiceStack.ServiceInterface.Auth;
  7. using Xunit;
  8. namespace EndToEnd
  9. {
  10. public class RegistrationTests
  11. : ServiceStackTestBase
  12. {
  13. [Fact]
  14. public void Can_register_a_new_user()
  15. {
  16. var client = new JsonServiceClient(ListeningOn);
  17. var response = client.Send(new Registration
  18. {
  19. UserName = "newuser",
  20. Password = "p@55w0rd",
  21. DisplayName = "New User",
  22. Email = "newuser@test.com",
  23. FirstName = "New",
  24. LastName = "User"
  25. });
  26. response.Should().NotBeNull();
  27. response.UserId.Should().NotBeNullOrEmpty();
  28. }
  29. [Fact]
  30. public void Can_create_a_widget()
  31. {
  32. var response = Client.Send(new CreateWidget
  33. {
  34. Name = "Widget One"
  35. });
  36. response.Should().NotBeNull();
  37. response.Widget.Id.Should().NotBeNullOrEmpty();
  38. response.Widget.Name.Should().Be("Widget One");
  39. }
  40. [Fact]
  41. public void Throws_validation_exception_when_bad_widget()
  42. {
  43. var validator = Host.Container.Resolve<IValidator<CreateWidget>>();
  44. validator.Should().NotBeNull();
  45. try
  46. {
  47. var response = Client.Post(new CreateWidget
  48. {
  49. Name = null
  50. });
  51. throw new Exception("Should Not Get Here!");
  52. }
  53. catch (WebServiceException wex)
  54. {
  55. wex.StatusCode.Should().Be(400);
  56. wex.ErrorMessage.Should().Be("'Name' should not be empty.");
  57. }
  58. }
  59. }
  60. }