Exemplo n.º 1
0
        public void Can_Get_Sound_By_Valid_Id()
        {
            // Arrange - creating a sound
            var sound = new TimerSound {
                Name = "Apple", Data = new byte[] { 0x01 }, ID = 2
            };

            // Arrange - create the mock repository
            var mockRepository = new Mock <IRepository <TimerSound> >();

            mockRepository.Setup(m => m.GetAll()).Returns(new[] {
                new TimerSound {
                    Name = "Orange", Data = new byte[] { 0x04 }, ID = 1
                },
                sound,
                new TimerSound {
                    Name = "Cabbage", Data = new byte[] { 0x07 }, ID = 3
                },
            }.AsQueryable());

            // Arrange - create a controller
            var targetController = new TimerController(null, mockRepository.Object, null);

            // Act - get the sound
            var result = targetController.GetSoundById(sound.ID);

            // Assert - check the method result type
            Assert.IsType <FileStreamResult>(result);
            Assert.Equal("application/octet-stream", (result as FileStreamResult)?.ContentType);
        }
Exemplo n.º 2
0
        public void Cannot_Get_Sound_By_Invalid_Id()
        {
            // Arrange - creating a sound
            var sound = new TimerSound {
                Name = "Apple", Data = new byte[] { 0x01 }, ID = 2
            };

            // Arrange - create the mock repository
            var mockRepository = new Mock <IRepository <TimerSound> >();

            mockRepository.Setup(m => m.GetAll()).Returns(new[] {
                new TimerSound {
                    Name = "Orange", Data = new byte[] { 0x04 }, ID = 1
                },
                new TimerSound {
                    Name = "Cabbage", Data = new byte[] { 0x07 }, ID = 3
                },
            }.AsQueryable());

            // Arrange - create a controller
            var targetController = new TimerController(null, mockRepository.Object, null);

            // Act - get the sound
            var result = targetController.GetSoundById(sound.ID);

            // Assert - check the method result type
            Assert.Null(result);
        }
Exemplo n.º 3
0
        public void Cannot_Delete_Nonexistent_Sound()
        {
            // Arrange - creating a sound
            var sound = new TimerSound {
                Name = "Apple", Data = new byte[] { 0x01 }, ID = 1
            };

            // Arrange - create the mock repository
            var mockRepository = new Mock <IRepository <TimerSound> >();

            mockRepository.Setup(m => m.GetAll()).Returns(new[] {
                new TimerSound {
                    Name = "Orange", Data = new byte[] { 0x04 }, ID = 2
                },
                new TimerSound {
                    Name = "Cabbage", Data = new byte[] { 0x07 }, ID = 3
                },
            }.AsQueryable());

            // Arrange - create a controller
            var target = new TimerController(null, mockRepository.Object, null);

            // Act - delete the product
            var result = target.DeleteSound(sound.ID);

            // Assert - ensure that the repository delete method was
            // called with the correct Product
            mockRepository.Verify(m => m.Delete(sound.ID));
            Assert.Equal(2, mockRepository.Object.GetAll().Count());
        }