コード例 #1
0
        public async Task AssignRandomTarget_ShouldCallHelper()
        {
            //Arrange
            var expectedPreyId   = 2;
            var expectedHunterId = 10;

            var dbElementsList = new List <DatabaseImageElement>()
            {
                new DatabaseImageElement()
                {
                    Id = expectedPreyId,
                    DescriptiveSentence = "test",
                    ImageContentUri     = "test",
                    ImageName           = "test",
                    PersonFirstName     = "test",
                    PersonLastName      = "test",
                    Score = 1
                },

                new DatabaseImageElement()
                {
                    Id = expectedPreyId,
                    DescriptiveSentence = "test",
                    ImageContentUri     = "test",
                    ImageName           = "test",
                    PersonFirstName     = "test",
                    PersonLastName      = "test",
                    Score = 1
                }
            };

            var fakeTargetElementHelper = A.Fake <ITargetElementHelper>();

            A.CallTo(() => fakeTargetElementHelper.AssignRandomTarget(expectedHunterId)).Returns(expectedPreyId);

            var targetElementController = new TargetElementController()
            {
                TargetElementHelper = fakeTargetElementHelper,
                Request             = new HttpRequestMessage()
            };

            //Act
            var result = targetElementController.AssignRandomTarget(expectedHunterId);

            //Assert
            A.CallTo(() => fakeTargetElementHelper.AssignRandomTarget(expectedHunterId)).MustHaveHappenedOnceExactly();

            var httpResponse = await result.ExecuteAsync(new CancellationToken());

            var jsonContent = await httpResponse.Content.ReadAsStringAsync();

            var expectedJson = JsonConvert.SerializeObject(expectedPreyId);

            jsonContent.ShouldBe(expectedJson);
        }
コード例 #2
0
        public async Task Post_ShouldCallHelper()
        {
            //Arrange
            var expectedId             = 1;
            var expectedHunterPersonId = 10;
            var expectedPreyPersonId   = 11;
            var expectedIsHunted       = false;

            var expectedTargetElement = new TargetElement()
            {
                Id             = expectedId,
                HunterPersonId = expectedHunterPersonId,
                PreyPersonId   = expectedPreyPersonId
            };

            var fakeTargetElementHelper = A.Fake <ITargetElementHelper>();

            A.CallTo(() =>
                     fakeTargetElementHelper.InsertNewTargetElement(expectedId, expectedHunterPersonId,
                                                                    expectedPreyPersonId, expectedIsHunted)).Returns(expectedTargetElement);

            var targetElementController = new TargetElementController()
            {
                TargetElementHelper = fakeTargetElementHelper,
                Request             = new HttpRequestMessage()
            };

            //Act
            var result = targetElementController.Post(expectedTargetElement);

            //Assert
            A.CallTo(() => fakeTargetElementHelper.InsertNewTargetElement(expectedId, expectedHunterPersonId,
                                                                          expectedPreyPersonId, expectedIsHunted)).MustHaveHappenedOnceExactly();

            var httpResponse = await result.ExecuteAsync(new CancellationToken());

            var jsonContent = await httpResponse.Content.ReadAsStringAsync();

            var expectedJson = JsonConvert.SerializeObject(expectedTargetElement);

            jsonContent.ShouldBe(expectedJson);
        }