예제 #1
0
        public void CreatePetCommand_Execute_Should_Call_UserMethod_AddPet()
        {
            // Arrange
            var petFactory = new Mock <IPetFactory>();
            var users      = new Mock <IUserRepository>();
            var pets       = new Mock <IPetRepository>();
            var writer     = new Mock <IWriter>();

            var pet      = new Mock <IPet>();
            var user     = new Mock <IUser>();
            var dataBase = new List <IPet>();

            user.SetupGet(m => m.PhoneNumber).Returns("123456");
            user.SetupGet(m => m.Pets).Returns(new List <IPet>());
            petFactory.Setup(m => m.CreateCat("Kitty", AnimalGenderType.female, 2)).Returns(pet.Object);
            users.SetupGet(m => m.Users).Returns(new List <IUser>()
            {
                user.Object
            });
            pets.SetupGet(m => m.Pets).Returns(new List <IPet>());

            var createPetCommand = new CreatePetCommand
                                       (petFactory.Object, users.Object, pets.Object, writer.Object);

            createPetCommand.Parameters = new List <string> {
                "createpet", "123456", "cat", "Kitty", "female", "2"
            };

            // Act
            createPetCommand.Execute();

            // Assert
            user.Verify(m => m.AddPet(pet.Object), Times.Once);
        }
예제 #2
0
        public void CreatePetCommand_Execute_Should_Throw_ArgumentNullException_When_User_Not_Found()
        {
            // Arrange
            var petFactory = new Mock <IPetFactory>();
            var users      = new Mock <IUserRepository>();
            var pets       = new Mock <IPetRepository>();
            var writer     = new Mock <IWriter>();

            var pet  = new Mock <IPet>();
            var user = new Mock <IUser>();

            user.SetupGet(m => m.PhoneNumber).Returns("123456");

            users.SetupGet(m => m.Users).Returns(new List <IUser>());

            var createPetCommand = new CreatePetCommand
                                       (petFactory.Object, users.Object, pets.Object, writer.Object);

            createPetCommand.Parameters = new List <string> {
                "createpet", "123456", "cat", "Kitty", "female", "2"
            };

            // Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => createPetCommand.Execute());
        }