예제 #1
0
        public void AddChatRoomCallsRepository()
        {
            // Arrange
            var chatRoomRepositoryMock = new Mock <IRepository <ChatRoom, long> >(MockBehavior.Strict);

            chatRoomRepositoryMock.Setup(repository => repository.Insert(It.IsAny <ChatRoom>())).Returns(1);
            ChatRoomManager chatRoomManager = new ChatRoomManager(chatRoomRepositoryMock.Object);

            ChatRoom chatRoom = new ChatRoom("room");

            // Act
            chatRoomManager.AddChatRoom(chatRoom);

            // Assert
            chatRoomRepositoryMock.Verify(repository => repository.Insert(It.IsAny <ChatRoom>()), Times.Once);
        }
예제 #2
0
        public void AddChatRoomCallsRepositoryWithSameParameter()
        {
            // Arrange
            ChatRoom parameter = null;
            var      chatRoomRepositoryMock = new Mock <IRepository <ChatRoom, long> >(MockBehavior.Strict);

            chatRoomRepositoryMock.Setup(repository => repository.Insert(It.IsAny <ChatRoom>()))
            .Callback <ChatRoom>((chatRoom) => parameter = chatRoom)
            .Returns(1);
            ChatRoomManager chatRoomManager = new ChatRoomManager(chatRoomRepositoryMock.Object);

            ChatRoom newChatRoom = new ChatRoom("room");

            // Act
            chatRoomManager.AddChatRoom(newChatRoom);

            // Assert
            Assert.AreEqual("room", parameter.Name);
            Assert.AreEqual(0, parameter.Messages.Count);
        }