Пример #1
0
        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);
        }
Пример #2
0
        public void ShouldThrowArgumentNullExceptionWhenUpdateWithEmptyMessage()
        {
            UpdateCommentModel model = new() { Message = string.Empty };

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

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }