public void Register_WithNullDisplayName_ReturnBadRequest() { // Arrange var appService = this.kernel.Get <IApplicationService>(); var controller = new RegisterV1Controller(appService); var request = new RegisterV1Request(); // Act var rawResult = controller.Post(request); // Assert Assert.IsInstanceOfType(rawResult, typeof(BadRequestErrorMessageResult)); var badResult = rawResult as BadRequestErrorMessageResult; Assert.IsFalse(string.IsNullOrWhiteSpace(badResult.Message)); var strBuilder = new StringBuilder(); strBuilder.AppendLine(string.Format(MessagesResx._CantBe_, nameof(Application.DisplayName), CommonsResx.Empty)); Assert.AreEqual(strBuilder.ToString(), badResult.Message); }
public void Register_DisplayNameMoreThan25Char_ReturnBadRequest() { // Arrange var repo = this.kernel.GetMock <IApplicationRepository>(); repo.Setup(a => a.SaveChanges()).Callback(() => { throw new DbEntityValidationException("Error"); }); var appService = this.kernel.Get <IApplicationService>(); var controller = new RegisterV1Controller(appService); var request = new RegisterV1Request { DisplayName = "ThisIsAplicaitionThatHaveVeryVeryLongName" }; // Act var rawResult = controller.Post(request); // Assert Assert.IsInstanceOfType(rawResult, typeof(BadRequestErrorMessageResult)); var badResult = rawResult as BadRequestErrorMessageResult; Assert.IsFalse(string.IsNullOrWhiteSpace(badResult.Message)); }
public void Register_WithValidDisplayName_ReturnOKStatusAndValidAppObject() { // Arrange var appService = this.kernel.Get <IApplicationService>(); var controller = new RegisterV1Controller(appService); var request = new RegisterV1Request { DisplayName = "Test" }; // Act var rawResult = controller.Post(request); // Assert Assert.IsInstanceOfType(rawResult, typeof(OkNegotiatedContentResult <RegisterV1Response>)); var okResult = rawResult as OkNegotiatedContentResult <RegisterV1Response>; Assert.IsNotNull(okResult.Content); Assert.IsFalse(string.IsNullOrWhiteSpace(okResult.Content.ApplicationId)); Assert.AreEqual(32, okResult.Content.ApplicationId.Length); Assert.IsFalse(string.IsNullOrWhiteSpace(okResult.Content.ApplicationSecret)); Assert.AreEqual(25, okResult.Content.ApplicationSecret.Length); Assert.IsFalse(string.IsNullOrWhiteSpace(okResult.Content.DisplayName)); Assert.AreEqual(request.DisplayName, okResult.Content.DisplayName); }