public async Task ReturnViewWithoutModelWhenSongIsUploadedSuccessfully() { string expectedMessage = "successfully"; var fileStub = new Mock <IFormFile>(); fileStub.Setup(f => f.ContentType).Returns(() => "audio"); fileStub.Setup(f => f.Length).Returns(() => SongMaxLength - 1); var uploadSongStub = new Mock <ICommandService <UploadSong> >(); SongFormModel model = new SongFormModel() { File = fileStub.Object }; // Arrange SongsController sut = CreateSongsController( uploadSong: uploadSongStub.Object); // Act var result = await sut.Upload(model) as WithMessageResult; var realAction = result.Action as ViewResult; // Assert Assert.IsNull(realAction.Model); }
public async Task ReturnViewWithSuccessMessageWhenSongIsUploadedSuccessfully() { string expectedMessage = "successfully"; var fileStub = new Mock <IFormFile>(); fileStub.Setup(f => f.ContentType).Returns(() => "audio"); fileStub.Setup(f => f.Length).Returns(() => SongMaxLength - 1); var uploadSongStub = new Mock <ICommandService <UploadSong> >(); SongFormModel model = new SongFormModel() { File = fileStub.Object }; // Arrange SongsController sut = CreateSongsController( uploadSong: uploadSongStub.Object); // Act var result = await sut.Upload(model) as WithMessageResult; // Assert Assert.AreEqual(typeof(WithMessageResult), result.GetType()); Assert.AreEqual("success", result.Type); StringAssert.Contains(expectedMessage, result.Message); }
public async Task ReturnViewWithErrorMessageWhenCommandServiceThrowNotFoundException() { string expectedMessage = "Fake message"; var fileStub = new Mock <IFormFile>(); fileStub.Setup(f => f.ContentType).Returns(() => "audio"); fileStub.Setup(f => f.Length).Returns(() => SongMaxLength - 1); var uploadSongStub = new Mock <ICommandService <UploadSong> >(); uploadSongStub.Setup(u => u.ExecuteAsync(It.IsAny <UploadSong>())) .Throws(new NotFoundException(expectedMessage)); SongFormModel model = new SongFormModel() { File = fileStub.Object }; // Arrange SongsController sut = CreateSongsController( uploadSong: uploadSongStub.Object); // Act var result = await sut.Upload(model) as WithMessageResult; // Assert Assert.AreEqual(typeof(WithMessageResult), result.GetType()); Assert.AreEqual("danger", result.Type); Assert.AreEqual(expectedMessage, result.Message); }
public void HaveRequiredAttribute(Type attrType) { // Arrange SongsController sut = CreateSongsController(Mock.Of <ICommandService <UploadSong> >()); // Act && Assert Assert.IsTrue(MethodHasAttribute( () => sut.Upload(default(SongFormModel)), attrType)); }
public async Task ReturnViewWithErrorMessageWhenSongFileIsNull() { SongFormModel model = new SongFormModel(); // Arrange SongsController sut = CreateSongsController(Mock.Of <ICommandService <UploadSong> >()); // Act var result = await sut.Upload(model) as WithMessageResult; // Assert Assert.AreEqual(typeof(WithMessageResult), result.GetType()); Assert.AreEqual("danger", result.Type); StringAssert.Contains("choose a file", result.Message); }
public async Task ReturnViewWithTheSameModelWhenSongFileIsNull() { SongFormModel model = new SongFormModel(); // Arrange SongsController sut = CreateSongsController(Mock.Of <ICommandService <UploadSong> >()); // Act var result = await sut.Upload(model) as WithMessageResult; var realAction = result.Action as ViewResult; // Assert Assert.IsNotNull(realAction.Model); Assert.AreSame(model, realAction.Model); }
public async Task ReturnViewWithErrorMessageWhenPassedFileTypeIsNotSong() { var fileStub = new Mock <IFormFile>(); fileStub.Setup(f => f.ContentType).Returns(() => "InvalidSongFile"); SongFormModel model = new SongFormModel() { File = fileStub.Object }; // Arrange SongsController sut = CreateSongsController(Mock.Of <ICommandService <UploadSong> >()); // Act var result = await sut.Upload(model) as WithMessageResult; // Assert Assert.AreEqual(typeof(WithMessageResult), result.GetType()); Assert.AreEqual("danger", result.Type); StringAssert.Contains("should be an audio", result.Message); }
public async Task ReturnViewWithErrorMessageWhenPassedFileIsTooLarge() { var fileStub = new Mock <IFormFile>(); fileStub.Setup(f => f.ContentType).Returns(() => "audio"); fileStub.Setup(f => f.Length).Returns(() => SongMaxLength + 1); SongFormModel model = new SongFormModel() { File = fileStub.Object }; // Arrange SongsController sut = CreateSongsController( uploadSong: Mock.Of <ICommandService <UploadSong> >()); // Act var result = await sut.Upload(model) as WithMessageResult; // Assert Assert.AreEqual(typeof(WithMessageResult), result.GetType()); Assert.AreEqual("danger", result.Type); StringAssert.Contains("no more than", result.Message); }