示例#1
0
        public async Task Handle_Text_Wrong_Message()
        {
            var fakeWord     = 0;
            var fakeMessage  = "fake";
            var fakeSequence = new List <int> {
                1, 2
            };
            var fakeRequest      = CreateFakeTextRequest(fakeWord, fakeMessage, fakeSequence);
            var fakeTranslations = CreateFakeTranslations("wrong");

            int lastKnownWordId = fakeRequest.Request.Session.ExpectedWord;

            _languageRepositoryMock.Setup(x => x.GetWordTranslationsAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(fakeTranslations));

            // Act
            var arcadeLogic = new ArcadeLogic(
                _languageRepositoryMock.Object,
                _translationsRepositoryMock.Object
                );
            var result = await arcadeLogic.HandleText(fakeRequest);

            // Assert
            Assert.AreEqual(result.ResponseCode, ResponseCodes.WrongAnswer);
            Assert.AreNotEqual(fakeRequest.Request.Session.ExpectedWord, lastKnownWordId);
        }
示例#2
0
        public async Task Handle_Text_Last_Word_In_Sequence()
        {
            // Arrange
            var fakeWord     = 2;
            var fakeMessage  = "fake";
            var fakeSequence = new List <int> {
                1, 2, 3
            };
            var fakeRequest       = CreateFakeTextRequest(fakeWord, fakeMessage, fakeSequence);
            var lastKnownSequence = new List <int>(fakeSequence);

            var fakeTranslations = CreateFakeTranslations(fakeMessage);

            _languageRepositoryMock.Setup(x => x.GetWordsCountAsync())
            .Returns(Task.FromResult(4));

            _languageRepositoryMock.Setup(x => x.GetWordTranslationsAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(fakeTranslations));

            // Act
            var arcadeLogic = new ArcadeLogic(
                _languageRepositoryMock.Object,
                _translationsRepositoryMock.Object
                );

            var result = await arcadeLogic.HandleText(fakeRequest);

            // Assert
            Assert.AreEqual(result.ResponseCode, ResponseCodes.OK);
            Assert.AreNotEqual(lastKnownSequence, fakeRequest.Request.Session.WordSequence);
            Assert.AreEqual(fakeRequest.Request.Session.ExpectedWord, 0);
        }
示例#3
0
        public async Task Handle_Text_Empty_Word_Sequence()
        {
            // Arrange
            var fakeWord    = 0;
            var fakeMessage = "fake";
            var fakeRequest = CreateFakeTextRequest(fakeWord, fakeMessage);

            // Act
            var arcadeLogic = new ArcadeLogic(
                _languageRepositoryMock.Object,
                _translationsRepositoryMock.Object
                );

            var result = await arcadeLogic.HandleText(fakeRequest);

            // Assert
            Assert.AreEqual(result.ResponseCode, ResponseCodes.LogicInternalError);
        }
示例#4
0
        public async Task Handle_Text_Word_Index_More_Than_Sequence_Count()
        {
            // Arrange
            var fakeWord     = 2;
            var fakeMessage  = "fake";
            var fakeSequence = new List <int> {
                1, 2
            };
            var fakeRequest       = CreateFakeTextRequest(fakeWord, fakeMessage, fakeSequence);
            var lastKnownSequence = new List <int>(fakeSequence);

            // Act
            var arcadeLogic = new ArcadeLogic(
                _languageRepositoryMock.Object,
                _translationsRepositoryMock.Object
                );

            var result = await arcadeLogic.HandleText(fakeRequest);

            // Assert
            Assert.AreEqual(result.ResponseCode, ResponseCodes.LogicInternalError);
        }
示例#5
0
        public async Task Handle_Text_Success()
        {
            // Arrange
            var fakeWord     = 0;
            var fakeMessage  = "fake";
            var fakeSequence = new List <int> {
                1, 2
            };
            var fakeRequest      = CreateFakeTextRequest(fakeWord, fakeMessage, fakeSequence);
            var fakeTranslations = CreateFakeTranslations(fakeMessage);

            _languageRepositoryMock.Setup(x => x.GetWordTranslationsAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(fakeTranslations));

            // Act
            var arcadeLogic = new ArcadeLogic(
                _languageRepositoryMock.Object,
                _translationsRepositoryMock.Object
                );
            var result = await arcadeLogic.HandleText(fakeRequest);

            // Assert
            Assert.AreEqual(result.ResponseCode, ResponseCodes.OK);
        }