コード例 #1
0
        public void NewUserIdIsZero()
        {
            // Arrange
            IIdentityProvider idProvider  = new SequentialIdentityProvider();
            IRepo <IUser>     userRepo    = new InMemoryRepo <IUser>();
            UserService       userService = new UserService(idProvider, userRepo);

            int expectedSessionId = 0;

            // Act
            userService.CreateUser("Alice", "trustno1");

            // Assert
            Assert.AreEqual(expectedSessionId, userRepo.Items.First().Id);
        }
コード例 #2
0
        public void NewMessageIdIsZero()
        {
            // Arrange
            string alicePassword = "******";
            IUser  alice         = new User(0, "Alice", new SHA256PasswordHandler(alicePassword));

            IIdentityProvider idProvider     = new SequentialIdentityProvider();
            IRepo <ISession>  sessionRepo    = new InMemoryRepo <ISession>();
            SessionService    sessionService = new SessionService(idProvider, sessionRepo);

            int expectedSessionId = 0;

            // Act
            sessionService.CreateSession(alice, alicePassword);

            // Assert
            Assert.AreEqual(expectedSessionId, sessionRepo.Items.First().Id);
        }
コード例 #3
0
        public void NewPrivateChatIdIsZero()
        {
            // Arrange
            IUser alice = new User(0, "Alice", new SHA256PasswordHandler("trustno1"));
            IUser bob   = new User(1, "Bob", new SHA256PasswordHandler("trustno1"));

            IIdentityProvider idProvider  = new SequentialIdentityProvider();
            IRepo <IChat>     chatRepo    = new InMemoryRepo <IChat>();
            ChatService       chatService = new ChatService(idProvider, chatRepo);

            int expectedChatId = 0;

            // Act
            chatService.CreatePrivateChat(alice, bob);

            // Assert
            Assert.AreEqual(expectedChatId, chatRepo.Items.First().Id);
        }
コード例 #4
0
        public void PrivateChatMessageSent()
        {
            // Arrange
            IUser alice = new User(0, "Alice", new SHA256PasswordHandler("trustno1"));
            IUser bob   = new User(1, "Bob", new SHA256PasswordHandler("trustno1"));

            IIdentityProvider idProvider     = new SequentialIdentityProvider();
            IRepo <IMessage>  messageRepo    = new InMemoryRepo <IMessage>();
            IChat             chat           = new PrivateChat(0, idProvider, messageRepo, alice, bob);
            MessageService    messageService = new MessageService();

            int expectedMessageId = 0;

            // Act
            messageService.TrySendMessage(alice, chat, "Hi, Bob! What are you up to?");

            // Assert
            Assert.AreEqual(expectedMessageId, messageRepo.Items.First().Id);
        }