public void ConvertToCoordinates_WhenCalled_ShouldConvertCoordinates(string symbolic, int expectedCord1, int expectedCord2)
        {
            var expectedCords = (expectedCord1, expectedCord2);
            var resultCords   = TestedService.ConvertToCoordinates(symbolic);

            resultCords.Should().Be(expectedCords, "returned cords should match expected");
        }
        public void ShouldUpdateRecord()
        {
            Guid   entityId         = Guid.NewGuid();
            int    newIntFieldValue = 15;
            string expectedSqlQuery = $"UPDATE [{TestedTableName}] SET [IntField] = @P1, [ModifiedOn] = @P2 WHERE [Id] = @P3";

            IDictionary <string, object> newValues = new Dictionary <string, object>()
            {
                { "IntField", newIntFieldValue }
            };
            IEnumerable <KeyValuePair <string, object> > expectedArguments = new[] {
                new KeyValuePair <string, object>("@P1", newIntFieldValue),
                new KeyValuePair <string, object>("@P2", DateTime.UtcNow),
                new KeyValuePair <string, object>("@P3", entityId),
            };

            TestedAffectedRowsCount = 10;

            TestedService.Update(entityId, newValues);
            var lastCommand = LastCommand;


            Assert.NotNull(lastCommand);
            Assert.Equal(expectedSqlQuery, lastCommand.Value.Key);
            Assert.NotNull(lastCommand.Value.Value);
            AssertArguments(expectedArguments, lastCommand.Value.Value);
        }
        public void ConvertToSymbolic_WhenCalledWithWrongData_ShouldThrow(int cord1, int cord2)
        {
            var pos = (cord1, cord2);

            var symbolic = TestedService.Invoking(x => x.ConvertToSymbolic(pos));

            symbolic.Should().Throw <ConvertToSymbolicException>().WithMessage($"Coords {cord1} {cord2} are invalid");
        }
Esempio n. 4
0
        public void ShouldThrowArgumentNullExceptionWhenCommentIdIsDefaultInGet()
        {
            Guid testedId = default;

            Action testedAction = () => TestedService.Get(testedId);

            ShouldThrowArgumentNullExceptionWhenCommentIdIsDefaultInternal(testedAction);
        }
        public void ConvertToSymbolic_WhenCalled_ShouldConvertProperly(int cord1, int cord2, string expectedSymbolic)
        {
            var pos = (cord1, cord2);

            var symbolic = TestedService.ConvertToSymbolic(pos);

            symbolic.Should().Be(expectedSymbolic, "converted coordinates should be same as expected");
        }
Esempio n. 6
0
        public void ShouldThrowEntityNotFoundExceptionWhenEntityNotFoundByIdInGet()
        {
            Guid   testedId             = Guid.NewGuid();
            string expectedErrorMessage = $"Entity \"Comment\" - \"{testedId}\" not found.";

            Action testedAction = () => TestedService.Get(testedId);

            ShouldThrowEntityNotFoundExceptionWhenEntityNotFoundByIdInternal(testedAction, expectedErrorMessage);
        }
Esempio n. 7
0
        public void RandomizeShips_WhenCalled_ShouldReturnRandomizedShips()
        {
            var randomizedShips = TestedService.RandomizeShips();

            randomizedShips.Count.Should().Be(3, "generator should return 3 ships");
            randomizedShips.SelectMany(x => x.Cells).All(x => x.Hit == false).Should().BeTrue("all ships should be untouched");
            randomizedShips.Where(x => x.Length == 3).Count().Should().Be(2, "2 ships with length 3 should be returned");
            randomizedShips.Where(x => x.Length == 4).Count().Should().Be(1, "1 ship with length 4 should be returned");
        }
Esempio n. 8
0
        public void ShouldAddCommentAndReturnNewId()
        {
            AddCommentModel model = new() { Message = "TestedMessage" };

            Guid result = TestedService.Add(model);

            Assert.NotEqual(Guid.Empty, result);
        }
    }
        public void ShouldNotDeleteCommentsWhenCommentIdsContainsOnlyGuidEmptyValues()
        {
            Guid[] commentIds = new[] { Guid.Empty };
            TestedService.Delete(commentIds);

            KeyValuePair <string, IEnumerable <object> >?lastCommand = LastCommand;

            Assert.Null(lastCommand);
        }
        public void ShouldDeleteComments()
        {
            Guid[] commentIds          = new[] { Guid.NewGuid() };
            string expectedCommandName = "Delete";

            Action testedAction = () => TestedService.Delete(commentIds);

            ShouldExecuteCommand(testedAction, expectedCommandName, new object[] { commentIds });
        }
Esempio n. 11
0
        public void ShouldReturnDescription()
        {
            string expectedDescription = ReturnedTestedComment.Description;
            Guid   testedId            = Guid.NewGuid();

            string result = TestedService.GetDescription(testedId);

            Assert.NotNull(result);
            Assert.NotEqual(string.Empty, result);
            Assert.Equal(expectedDescription, result);
        }
Esempio n. 12
0
        public void ShouldExecuteQuery()
        {
            string expectedSqlQuery = $"SELECT * FROM [{TestedTableName}]";

            TestedService.Get();
            var lastQuery = LastQuery;

            Assert.NotNull(lastQuery);
            Assert.Equal(expectedSqlQuery, lastQuery.Value.Key);
            Assert.Null(lastQuery.Value.Value);
        }
Esempio n. 13
0
        public void ShouldThrowArgumentNullExceptionWhenAddWithEmptyModel()
        {
            AddCommentModel model = null;

            var exception =
                Record.Exception(
                    () => TestedService.Add(model)
                    );

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
Esempio n. 14
0
        public void ShouldThrowArgumentNullExceptionWhenEntityIsNull()
        {
            TestedDataProviderEntity entity = null;

            Exception exception =
                Record.Exception(
                    () => TestedService.Add(entity)
                    );

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
        public void ShouldThrowArgumentNullExceptionWhenParameterIsNull()
        {
            Guid[] commentIds = null;

            var exception =
                Record.Exception(
                    () => TestedService.Delete(commentIds)
                    );

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
        public void ShouldThrowArgumentNullExceptionWhenArgumentIsNull()
        {
            Guid[] entityIds = null;

            Exception exception =
                Record.Exception(
                    () => TestedService.Delete(entityIds)
                    );

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
Esempio n. 17
0
        public void ShouldThrowArgumentNullExceptionWhenUpdateWithEmptyMessage()
        {
            UpdateCommentModel model = new() { Message = string.Empty };

            var exception =
                Record.Exception(
                    () => TestedService.Update(model)
                    );

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
        public void ShouldThrowArgumentNullExceptionWhenEntityValuesIsEmpty()
        {
            Guid entityId = Guid.NewGuid();
            IDictionary <string, object> newValues = new Dictionary <string, object>();

            Exception exception =
                Record.Exception(
                    () => TestedService.Update(entityId, newValues)
                    );

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
        public void ShouldIncrementCommentAppearanceCount()
        {
            Guid   testedCommentId     = Guid.NewGuid();
            string expectedCommandName = "Update";
            long   newAppearanceCount  = ReturnedTestedComment.AppearanceCount + 1;
            IDictionary <string, object> secondExpectedArgument = new Dictionary <string, object> {
                { "AppearanceCount", newAppearanceCount }
            };

            Action testedAction = () => TestedService.Increment(testedCommentId);

            ShouldExecuteCommand(testedAction, expectedCommandName, new object[] { testedCommentId, secondExpectedArgument });
        }
        public void ShouldNotExecuteSqlCommandWhenEntityValuesContainsOnlyDefaultEntityFields()
        {
            Guid entityId = Guid.NewGuid();
            IDictionary <string, object> newValues = new Dictionary <string, object>()
            {
                { "CreatedOn", DateTime.UtcNow }
            };

            TestedService.Update(entityId, newValues);
            var lastCommand = LastCommand;

            Assert.Null(lastCommand);
        }
        public void ShouldNotExecuteSqlCommandWhenEntityValuesContainsFieldsNotPresentedInEntity()
        {
            Guid entityId = Guid.NewGuid();
            IDictionary <string, object> newValues = new Dictionary <string, object>()
            {
                { "TestedNotExistedPropeprty", DateTime.UtcNow }
            };

            TestedService.Update(entityId, newValues);
            var lastCommand = LastCommand;

            Assert.Null(lastCommand);
        }
        public void ShouldNotExecuteSqlCommandWhenEntityValuesContainsDefaultValues()
        {
            Guid entityId = Guid.NewGuid();
            IDictionary <string, object> newValues = new Dictionary <string, object>()
            {
                { "IntField", 0 }
            };

            TestedService.Update(entityId, newValues);
            var lastCommand = LastCommand;

            Assert.Null(lastCommand);
        }
Esempio n. 23
0
        public void ShouldExecuteQuery()
        {
            Guid   testedId         = Guid.NewGuid();
            string expectedSqlQuery = $"SELECT * FROM [{TestedTableName}] WHERE Id = @P1";
            IEnumerable <KeyValuePair <string, object> > expectedArguments = new[] { new KeyValuePair <string, object>("P1", testedId) };

            TestedService.Get(testedId);
            var lastQuery = LastQuery;

            Assert.NotNull(lastQuery);
            Assert.Equal(expectedSqlQuery, lastQuery.Value.Key);
            Assert.NotNull(lastQuery.Value.Value);
            AssertArguments(expectedArguments, lastQuery.Value.Value);
        }
Esempio n. 24
0
        public void ShouldReturnComment()
        {
            Guid testedId = Guid.NewGuid();
            ExtendedCommentModel expectedComment = new()
            {
                Id          = ReturnedTestedComment.Id,
                Message     = ReturnedTestedComment.Message,
                Description = ReturnedTestedComment.Description
            };

            ExtendedCommentModel result = TestedService.Get(testedId);

            Assert.NotNull(result);
            Assert.Equal(expectedComment.Id, result.Id);
            Assert.Equal(expectedComment.Description, result.Description);
            Assert.Equal(expectedComment.Message, result.Message);
        }
    }
        public void ShouldThrowExceptionWhenAffectedRowsIsZero()
        {
            string expectedExceptionMessage = "Update command performed with empty result, no record was updated.";
            Guid   entityId = Guid.NewGuid();
            IDictionary <string, object> newValues = new Dictionary <string, object>()
            {
                { "IntField", 10 }
            };

            TestedAffectedRowsCount = 0;

            Exception exception =
                Record.Exception(
                    () => TestedService.Update(entityId, newValues)
                    );

            Assert.NotNull(exception);
            Assert.Equal(expectedExceptionMessage, exception.Message);
        }
        public void ShouldReturnMappedComments()
        {
            int          expectedCommentsCount = 1;
            CommentModel expectedCommentModel  = new()
            {
                Id = ReturnedTestedComment.Id,
                AppearanceCount = ReturnedTestedComment.AppearanceCount,
                Message         = ReturnedTestedComment.Message
            };

            IEnumerable <CommentModel> result = TestedService.Get();
            var firstItem = result.FirstOrDefault();

            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.Equal(expectedCommentsCount, result.Count());
            Assert.NotNull(firstItem);
            Assert.Equal(expectedCommentModel.Id, firstItem.Id);
            Assert.Equal(expectedCommentModel.AppearanceCount, firstItem.AppearanceCount);
            Assert.Equal(expectedCommentModel.Message, firstItem.Message);
        }
    }