Пример #1
0
        public void CreateUniversityAsync()
        {
            //Arrange
            _mockUnitOfWork.Setup(_mockUnitOfWork => _mockUnitOfWork.Universities.AddAsync(mockUniversity, It.IsAny <CancellationToken>())).Returns(Task.FromResult(mockUniversity));

            //Act
            var expected = _universityService.CreateUniversityAsync(mockUniversityCreateDto, It.IsAny <CancellationToken>()).Result;

            var newId = expected.Id;

            var newMockUniversityDto = new UniversityDto()
            {
                Id   = newId,
                Name = mockUniversityCreateDto.Name
            };

            var sameAsExpected = expected;

            //Assert
            //Assert.AreEqual(expected, newMockUniversityDto);//classic model of assertions(older)
            Assert.That(expected, Is.EqualTo(newMockUniversityDto));//constraint model of assertions(newer)
            //Assert.That(expected, Is.SameAs(newMockUniversityDto), "fails because it only compares references and not values");//fails because it only compares references and not values
            //Assert.That(expected, Is.SameAs(sameAsExpected));//passes
            //Assert.That(expected, Has.Exactly(1).Items);//fails because of the type of expected
            //Assert.That(expected,Is.Not.Null);
            //_mockUnitOfWork.SetupAllProperties();
        }
Пример #2
0
        public async Task <ActionResult> CreateUniversity([FromBody] CreateUniversityDto createUniversityDto, CancellationToken ct)
        {
            var universityToReturn = await _universityService.CreateUniversityAsync(createUniversityDto, ct);

            if (universityToReturn == null)
            {
                return(BadRequest());
            }

            return(CreatedAtRoute("GetUniversity", new { id = universityToReturn.Id }, universityToReturn));
        }
Пример #3
0
 public async Task <ActionResult <UniversityDto> > AddUniversityAsync([FromBody] UniversityAddRequest request)
 {
     return(_viewMapper.ServiceResultToContentResult(await _universityService.CreateUniversityAsync(request)));
 }