示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        public void HaveRequiredAttribute(Type attrType)
        {
            // Arrange
            SongsController sut = CreateSongsController(Mock.Of <ICommandService <UploadSong> >());

            // Act && Assert
            Assert.IsTrue(MethodHasAttribute(
                              () => sut.Upload(default(SongFormModel)),
                              attrType));
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }