Пример #1
0
        public void AddRange_TwoValidRaces_CountIncreasedByTwo()
        {
Start:
            var notExistsRaceCode1 = PreDefinedData.GetNotExistsRaceCode();
            var notExistsRaceCode2 = PreDefinedData.GetNotExistsRaceCode();

            if (notExistsRaceCode1 == notExistsRaceCode2)
            {
                goto Start;
            }

            var newRaces = new Collection <ReferenceRace>
            {
                new ReferenceRace {
                    Code = notExistsRaceCode1, LongName = ""
                },
                new ReferenceRace {
                    Code = notExistsRaceCode2, LongName = ""
                }
            };

            UnitOfWork.ReferenceRaces.AddRange(newRaces);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceRaces.GetAll();

            Assert.That(result.Count, Is.EqualTo(PreDefinedData.ReferenceRaces.Length + newRaces.Count));
        }
Пример #2
0
        public void AddRange_TwoValidRacesDuplicated_ThrowsInvalidOperationException()
        {
            var notExistsRaceCode = PreDefinedData.GetNotExistsRaceCode();
            var newRaces          = new Collection <ReferenceRace>
            {
                new ReferenceRace {
                    Id = int.MaxValue, Code = notExistsRaceCode, LongName = ""
                },
                new ReferenceRace {
                    Id = int.MaxValue, Code = notExistsRaceCode, LongName = ""
                }
            };

            Assert.That(() => UnitOfWork.ReferenceRaces.AddRange(newRaces),
                        Throws.InvalidOperationException);
        }
Пример #3
0
        public void Add_ValidRaceNotExists_FetchNewRace()
        {
            var notExistsRaceCode = PreDefinedData.GetNotExistsRaceCode();
            var newReferenceRace  = new ReferenceRace
            {
                Code     = notExistsRaceCode,
                LongName = notExistsRaceCode
            };

            UnitOfWork.ReferenceRaces.Add(newReferenceRace);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceRaces.Get(newReferenceRace.Id);

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

            AssertHelper.AreObjectsEqual(newReferenceRace, result);
        }
Пример #4
0
        public async Task Update_InvalidRace_HttpNotFound()
        {
            // Arrange
            var notExistsRaceCode = PreDefinedData.GetNotExistsRaceCode();
            var path            = GetRelativePath(nameof(ReferenceRacesController), int.MaxValue.ToString());
            var apiUpdatingRace = new ReferenceRaceDto
            {
                Id       = int.MaxValue,
                Code     = notExistsRaceCode,
                LongName = "Update Test"
            };

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

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
Пример #5
0
        public async Task Create_ValidPayload_HttpCreatedAndReturnsNewRace()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceRacesController));
            var notExistsRaceCode = PreDefinedData.GetNotExistsRaceCode();
            var newRaceDto        = new ReferenceRaceDto
            {
                Code         = notExistsRaceCode,
                LongName     = "New Race",
                CreatedDate  = DateTime.UtcNow,
                CreatedBy    = CreatedModifiedBy,
                ModifiedDate = DateTime.UtcNow,
                ModifiedBy   = CreatedModifiedBy
            };

            // Act
            var response = await Client.PostAsync(path, new StringContent(
                                                      JsonConvert.SerializeObject(newRaceDto),
                                                      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 <ReferenceRaceDto>(responseString);

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

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