示例#1
0
        public void AddRange_TwoValidNameSuffixes_CountIncreasedByTwo()
        {
Start:
            var notExistsNameSuffixCode1 = PreDefinedData.GetNotExistsNameSuffixCode();
            var notExistsNameSuffixCode2 = PreDefinedData.GetNotExistsNameSuffixCode();

            if (notExistsNameSuffixCode1 == notExistsNameSuffixCode2)
            {
                goto Start;
            }

            var newNameSuffixes = new Collection <ReferenceNameSuffix>
            {
                new ReferenceNameSuffix {
                    Code = notExistsNameSuffixCode1, LongName = ""
                },
                new ReferenceNameSuffix {
                    Code = notExistsNameSuffixCode2, LongName = ""
                }
            };

            UnitOfWork.ReferenceNameSuffixes.AddRange(newNameSuffixes);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceNameSuffixes.GetAll();

            Assert.That(result.Count, Is.EqualTo(PreDefinedData.ReferenceNameSuffixes.Length + newNameSuffixes.Count));
        }
示例#2
0
        public void AddRange_TwoValidNameSuffixesDuplicated_ThrowsInvalidOperationException()
        {
            var notExistsNameSuffixCode = PreDefinedData.GetNotExistsNameSuffixCode();
            var newNameSuffixes         = new Collection <ReferenceNameSuffix>
            {
                new ReferenceNameSuffix {
                    Id = int.MaxValue, Code = notExistsNameSuffixCode, LongName = ""
                },
                new ReferenceNameSuffix {
                    Id = int.MaxValue, Code = notExistsNameSuffixCode, LongName = ""
                }
            };

            Assert.That(() => UnitOfWork.ReferenceNameSuffixes.AddRange(newNameSuffixes),
                        Throws.InvalidOperationException);
        }
示例#3
0
        public void Add_ValidNameSuffixNotExists_FetchNewNameSuffix()
        {
            var notExistsNameSuffixCode = PreDefinedData.GetNotExistsNameSuffixCode();
            var newReferenceNameSuffix  = new ReferenceNameSuffix
            {
                Code     = notExistsNameSuffixCode,
                LongName = notExistsNameSuffixCode
            };

            UnitOfWork.ReferenceNameSuffixes.Add(newReferenceNameSuffix);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceNameSuffixes.Get(newReferenceNameSuffix.Id);

            Assert.That(result, Is.Not.Null);

            AssertHelper.AreObjectsEqual(newReferenceNameSuffix, result);
        }
示例#4
0
        public async Task Update_InvalidNameSuffix_HttpNotFound()
        {
            // Arrange
            var notExistsNameSuffixCode = PreDefinedData.GetNotExistsNameSuffixCode();
            var path = GetRelativePath(nameof(ReferenceNameSuffixesController), int.MaxValue.ToString());
            var apiUpdatingNameSuffix = new ReferenceNameSuffixDto
            {
                Id       = int.MaxValue,
                Code     = notExistsNameSuffixCode,
                LongName = "Update Test"
            };

            // Act
            var response = await Client.PutAsync(path, new StringContent(
                                                     JsonConvert.SerializeObject(apiUpdatingNameSuffix),
                                                     Encoding.UTF8,
                                                     JsonMediaType));

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
示例#5
0
        public async Task Create_ValidPayload_HttpCreatedAndReturnsNewNameSuffix()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceNameSuffixesController));
            var notExistsNameSuffixCode = PreDefinedData.GetNotExistsNameSuffixCode();
            var newNameSuffixDto        = new ReferenceNameSuffixDto
            {
                Code         = notExistsNameSuffixCode,
                LongName     = "New NameSuffix",
                CreatedDate  = DateTime.UtcNow,
                CreatedBy    = CreatedModifiedBy,
                ModifiedDate = DateTime.UtcNow,
                ModifiedBy   = CreatedModifiedBy
            };

            // Act
            var response = await Client.PostAsync(path, new StringContent(
                                                      JsonConvert.SerializeObject(newNameSuffixDto),
                                                      Encoding.UTF8,
                                                      JsonMediaType));

            var responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.DoesNotThrow(
                () => response.EnsureSuccessStatusCode(),
                string.Format(HttpExceptionFormattedMessage, responseString));
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created));

            var apiReturnedObject =
                JsonConvert.DeserializeObject <ReferenceNameSuffixDto>(responseString);

            Assert.That(apiReturnedObject.Id, Is.GreaterThan(0));

            newNameSuffixDto.Id = apiReturnedObject.Id;
            AssertHelper.AreObjectsEqual(apiReturnedObject, newNameSuffixDto);
        }