Пример #1
0
        public void AddLeft(string id, string left)
        {
            if (string.IsNullOrWhiteSpace(left))
            {
                throw new ArgumentNullException("Left");
            }
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException("Id");
            }
            var newValue = new Comparison()
            {
                ComparisonId = id, Left = left
            };
            //We check if the id already exists
            var entity = _comparisonRepository.Get(id);

            if (entity != null)
            {
                //If It does exist, we update the value
                entity.Left = newValue.Left;
                _comparisonRepository.Update(entity);
            }
            else
            {
                _comparisonRepository.Insert(newValue);
            }
        }
        public async Task InsertOrUpdateAsync(ComparisonInsertRequestDto requestDto)
        {
            Comparison comparison = await _comparisonRepository.GetByIdAsync(requestDto.Id);

            bool insert = false;

            if (comparison == null)
            {
                comparison    = new Comparison();
                comparison.Id = requestDto.Id;
                insert        = true;
            }

            if (requestDto.ValueType == ComparisonEnum.Left)
            {
                comparison.LeftArray = requestDto.Value;
            }
            else
            {
                comparison.RightArray = requestDto.Value;
            }

            if (insert)
            {
                await _comparisonRepository.InsertAsync(comparison);
            }
            else
            {
                _comparisonRepository.Update(comparison);
            }

            await _applicationDbContext.SaveChangesAsync();
        }
Пример #3
0
        public void Given_Valid_Data_When_Update_Right_Should_Update()
        {
            //Arrange
            var id           = _fixture.Create <string>();
            var base64string = _fixture.Create <string>().Base64Encode();
            var comparison   = new Comparison()
            {
                ComparisonId = id, Left = base64string, Right = base64string
            };

            _repository.Insert(comparison);
            comparison.Right = _fixture.Create <string>().Base64Encode();

            //Act
            _repository.Update(comparison);

            //Assert
            var saved = _repository.Get(comparison.ComparisonId);

            Assert.IsNotNull(saved);
            Assert.AreEqual(saved.Right, comparison.Right);
        }