Esempio n. 1
0
        public void Post_Invalid_Song_Returns_Bad_Request()
        {
            Song s = new Song()
            {
                IsDeleted = true
            };

            _songsController.ModelState.AddModelError("Title", "required");
            var result = _songsController.Post(s);

            Assert.IsType <BadRequestResult>(result);
        }
Esempio n. 2
0
        public async Task Post_GivenSongDoesNotExist_CreatesSongInDatabase()
        {
            var songRequest = new SongRequest
            {
                Artist     = "artist",
                Difficulty = "difficulty",
                Level      = 5,
                Name       = "name",
            };

            var expectedSong = new Song
            {
                Artist     = songRequest.Artist,
                Difficulty = songRequest.Difficulty,
                Level      = songRequest.Level,
                Name       = songRequest.Name
            };

            var actionResult = await _songsController.Post(songRequest);

            var createdResult = Assert.IsType <CreatedResult>(actionResult.Result);
            var id            = Guid.Parse(createdResult.Location.Substring(createdResult.Location.LastIndexOf("/") + 1));

            expectedSong.Id = id;

            var newSong = await _fixture._context.Songs.FindAsync(id);

            Assert.Equal(expectedSong, newSong);
        }
Esempio n. 3
0
        public void SongsPost()
        {
            var testSubject = new SongsController(_testRepo);
            var testObject  = new Song()
            {
                Id = 20, Artist = "TestArtist"
            };

            testSubject.Post(testObject);
            Assert.IsTrue(_testRepo.GetAll().Count > 20);
        }
        public async Task Post_ShouldReturnNewSong_With_SongEndpoint()
        {
            var songRequest = new SongRequest
            {
                Artist     = "Artist1",
                Difficulty = "Hard",
                Level      = 5,
                Name       = "Song1"
            };

            var songGuid             = Guid.Parse("F531D138-44F2-4400-A21B-C3D9A3C8D485");
            var expectedSongResponse = new SongResponse
            {
                Artist     = songRequest.Artist,
                Difficulty = songRequest.Difficulty,
                Id         = songGuid,
                Level      = songRequest.Level,
                Name       = songRequest.Name
            };

            _songService.Add(Arg.Any <Song>()).Returns(
                args => Task.FromResult <Song>(new Song
            {
                Id         = songGuid,
                Artist     = args.ArgAt <Song>(0).Artist,
                Difficulty = args.ArgAt <Song>(0).Difficulty,
                Level      = args.ArgAt <Song>(0).Level,
                Name       = args.ArgAt <Song>(0).Name
            }));

            var actionResult = await _songsController.Post(songRequest);

            var createdResult = Assert.IsType <CreatedResult>(actionResult.Result);

            Assert.Equal($"/songs/{songGuid}", createdResult.Location);
            var songResponse = Assert.IsType <SongResponse>(createdResult.Value);

            Assert.Equal(expectedSongResponse, songResponse);
            await _coreDataService.Received(1).SaveChanges();
        }