public async Task Get_By_Id_Should_Return_Entity_With_Matching_Id()
        {
            // Arrange
            var existingContainer = TestFixture.Create <BeerContainer>();
            await Context.BeerContainers.AddAsync(existingContainer);

            await Context.SaveChangesAsync();

            // Act
            var result = await _controller.Get(existingContainer.BeerContainerId);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <OkObjectResult>();

            var okResult           = result as OkObjectResult;
            var retrievedContainer = okResult.Value as BeerContainer;

            retrievedContainer.ContainerType
            .Should()
            .Be(existingContainer.ContainerType);
        }
Exemplo n.º 2
0
        public async Task GetByIdAsync_Should_Return_Item_With_Matching_Id()
        {
            // Arrange
            var style = TestFixture.Create <BeerStyle>();
            await Context.BeerStyles.AddAsync(style);

            await Context.SaveChangesAsync();

            // Act
            var actualStyle = await _controller.GetByIdAsync(style.StyleId);

            // Assert
            actualStyle.Should()
            .NotBeNull();

            actualStyle.Should()
            .BeOfType <OkObjectResult>();

            var okResult      = actualStyle as OkObjectResult;
            var returnedStyle = okResult.Value as BeerStyle;

            returnedStyle.StyleName
            .Should()
            .Be(style.StyleName);
        }
Exemplo n.º 3
0
        public async Task PostAsync_Should_Add_Item_To_Database()
        {
            // Arrange
            var createRequest = TestFixture.Create <CreateBeerStyle>();
            var itemToCreate  = TestFixture.Create <BeerStyle>();

            _mockMapper.Setup(it => it.Map <BeerStyle>(createRequest))
            .Returns(itemToCreate);

            // Act
            var result = await _controller.PostAsync(createRequest);

            // Assert
            TestMockRepository.VerifyAll();

            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <CreatedAtActionResult>();

            var dbItem = await Context.BeerStyles.FindAsync(itemToCreate.StyleId);

            dbItem.Should()
            .NotBeNull();

            dbItem.StyleName
            .Should()
            .Be(itemToCreate.StyleName);
        }
        public async Task PutAsync_Should_Update_Existing_Container()
        {
            // Arrange
            var existingItem  = TestFixture.Create <BeerContainer>();
            var updateRequest = TestFixture.Build <UpdateBeerContainer>()
                                .With(_ => _.BeerContainerId, existingItem.BeerContainerId)
                                .Create();

            await Context.BeerContainers.AddAsync(existingItem);

            await Context.SaveChangesAsync();

            // Act
            var result = await _controller.PutAsync(updateRequest);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <OkObjectResult>();

            var okResult         = result as OkObjectResult;
            var updatedContainer = okResult.Value as BeerContainer;

            updatedContainer.ContainerType
            .Should()
            .Be(updatedContainer.ContainerType);

            var dbItem = await Context.BeerContainers.FindAsync(updateRequest.BeerContainerId);

            dbItem.ContainerType
            .Should()
            .Be(updatedContainer.ContainerType);
        }
Exemplo n.º 5
0
        public async Task GetById_Should_Return_Item_With_Matching_Id()
        {
            // Arrange
            var existingItem = TestFixture.Create <CellarItem>();
            await Context.CellarItems.AddAsync(existingItem);

            await Context.SaveChangesAsync();

            // Act
            var result = await _controller.GetById(existingItem.CellarItemId);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <OkObjectResult>();

            var returnedItem = ((result as OkObjectResult).Value as CellarItem);

            returnedItem.Should()
            .NotBeNull();

            returnedItem.CellarItemId
            .Should()
            .Be(existingItem.CellarItemId);
        }
        public async Task PostAsync_Should_Save_New_Container_To_Database()
        {
            // Arrange
            var containerToSave = TestFixture.Create <CreateBeerContainer>();
            var mappedContainer = TestFixture.Create <BeerContainer>();

            _mockMapper.Setup(it => it.Map <BeerContainer>(containerToSave))
            .Returns(mappedContainer);

            // Act
            var result = await _controller.PostAsync(containerToSave);

            // Assert
            TestMockRepository.VerifyAll();

            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <CreatedAtActionResult>();

            var dbItem = await Context.BeerContainers.FirstOrDefaultAsync(_ => _.ContainerType == mappedContainer.ContainerType);

            dbItem.Should()
            .NotBeNull();
        }
 public RegisterModelValidatorShould()
 {
     fixture     = TestFixture.Create();
     sut         = fixture.Create <RegisterModelValidator>();
     model       = fixture.Create <RegisterModel>();
     model.Email = "*****@*****.**";
 }
        public void GettingASingleDisputeByItsId_WhenItExists_ReturnsOkStatusCode200()
        {
            // Arrange
            const int disputeId          = 1234567;
            const int expectedStatusCode = 200;

            var dispute = TestFixture.Create <DisputeModel>();

            mockDataAccessCradle
            .Setup(dataAccessCradle => dataAccessCradle.GetItemAsync(It.IsAny <Func <Task <DisputeModel> > >()))
            .Returns(Task.FromResult(dispute));

            var controller =
                new DisputesController(
                    mockDataAccessCradle.Object,
                    mockDisputeRepository.Object,
                    mockIncludeReader.Object,
                    mockPageInformationProvider.Object,
                    mockDisputeFormatter.Object,
                    mockDisputeCollectionFormatter.Object,
                    mockTelemetryClient.Object);

            // Act
            var result = controller.GetDisputesByDisputeId(disputeId).GetAwaiter().GetResult();

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
        }
        public SignInUserModelValidatorShould()
        {
            var fixture = TestFixture.Create();

            model       = fixture.Create <SignInUserModel>();
            model.Email = "*****@*****.**";
            sut         = new SignInUserModelValidator();
        }
Exemplo n.º 10
0
        public TenantServiceShould()
        {
            var fixture = TestFixture.Create();

            testUser        = fixture.Create <PlannerAppUser>();
            mockHttpContext = MockHttpContext.CreateAuthenticatedHttpContext();
            var httpContextMock = new Mock <IHttpContextAccessor>();

            httpContextMock.Setup(m => m.HttpContext)
            .Returns(mockHttpContext);
            userManagerWrapperMock = new Mock <IUserManagerWrapper>();
            userManagerWrapperMock.Setup(m => m.FindByNameAsync(It.IsAny <string>())).ReturnsAsync(testUser);
            sut = new TenantService(httpContextMock.Object, userManagerWrapperMock.Object);
        }
Exemplo n.º 11
0
        public void GetAllStudentName()
        {
            //Arrange
            var studentBusinesstest = TestFixture.Create <Task <string> >();

            _studentRepository.Setup(x => x.GetAllStudentName()).Returns(studentBusinesstest);

            //Act
            var result = _target.GetAllStudentName();

            //Assert
            MockBaseRepository.VerifyAll();
            Assert.NotNull(result);
        }
Exemplo n.º 12
0
        public void GetAllStudentById()
        {
            //Arrange
            var studentBusiness = TestFixture.Create <Task <StudentDTOs> >();

            _studentRepository.Setup(x => x.GetStudentByID(It.IsAny <int>())).Returns(studentBusiness);

            //Act
            var result = _target.GetStudentByID(1);

            //Assert
            MockBaseRepository.VerifyAll();
            Assert.NotNull(result);
        }
Exemplo n.º 13
0
        public void DeleteStudentById()
        {
            //Arrange
            var studentBusinesstest = TestFixture.Create <Task <bool> >();

            _studentRepository.Setup(x => x.DeleteStudentById(It.IsAny <int>())).Returns(studentBusinesstest);

            //Act
            var result = _target.DeleteStudentById(1);

            //Assert
            MockBaseRepository.VerifyAll();
            Assert.NotNull(result);
        }
Exemplo n.º 14
0
        public async Task Put_Should_Update_Existing_Item()
        {
            // Arrange
            var updateRequest = TestFixture.Create <UpdateCellarItem>();
            var itemToUpdate  = TestFixture.Build <CellarItem>()
                                .With(_ => _.CellarItemId, updateRequest.CellarItemId)
                                .With(_ => _.BeerStyleId, updateRequest.BeerStyleId)
                                .With(_ => _.BeerContainerId, updateRequest.BeerContainerId)
                                .Create();

            var style = TestFixture.Build <BeerStyle>()
                        .With(_ => _.StyleId, updateRequest.BeerStyleId)
                        .Create();

            var container = TestFixture.Build <BeerContainer>()
                            .With(_ => _.BeerContainerId, updateRequest.BeerContainerId)
                            .Create();

            await Context.BeerStyles.AddAsync(style);

            await Context.BeerContainers.AddAsync(container);

            await Context.CellarItems.AddAsync(itemToUpdate);

            await Context.SaveChangesAsync();


            // Act
            var result = await _controller.Put(updateRequest);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <OkObjectResult>();

            var updatedItem = ((result as OkObjectResult).Value as CellarItem);

            updatedItem.Should()
            .NotBeNull();

            updatedItem.CellarItemId
            .Should()
            .Be(updateRequest.CellarItemId);

            updatedItem.ItemName
            .Should();
        }
Exemplo n.º 15
0
        public async Task ShouldSearchNormalizedTag(string tag, string expected)
        {
            // Assert
            var fixture = new TestFixture <SearchDocumentsByTagQueryHandler>();
            var query   = new SearchDocumentsByTagQuery(tag);

            fixture.Freeze <ITokensRepository>().FindByTagAsync(expected, CancellationToken.None)
            .Returns(fixture.Create <TokenEntity>());

            // Act
            var result = await fixture.Sut.Handle(query, CancellationToken.None);

            // Assert
            result.Documents.Should().NotBeEmpty();
        }
        public async Task DeleteAsync_Should_Return_NotFound_When_Id_Does_Not_Exist()
        {
            // Arrange
            var item = TestFixture.Create <BeerContainer>();

            // Act
            var result = await _controller.DeleteAsync(item.BeerContainerId);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <NotFoundResult>();
        }
Exemplo n.º 17
0
        public void UpdateStudentTest()
        {
            //Arrange
            var studentBusiness     = TestFixture.Create <StudentDTOs>();
            var studentBusinesstest = TestFixture.Create <Task <bool> >();

            _studentRepository.Setup(x => x.UpdateStudent(It.IsAny <int>(), It.IsAny <Student>())).Returns(studentBusinesstest);

            //Act
            var result = _target.Update(1, studentBusiness);

            //Assert
            MockBaseRepository.VerifyAll();
            Assert.NotNull(result);
        }
Exemplo n.º 18
0
        public async Task Put_Should_Return_Not_Found_When_Item_Does_Not_Exist()
        {
            // Arrange
            var item = TestFixture.Create <UpdateCellarItem>();

            // Act
            var result = await _controller.Put(item);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <NotFoundResult>();
        }
Exemplo n.º 19
0
        public async Task Delete_Should_Return_NotFound_When_Item_Does_Not_Exist()
        {
            // Arrange
            var id = TestFixture.Create <int>();

            // Act
            var result = await _controller.Delete(id);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <NotFoundResult>();
        }
        public async Task PutAsync_Should_Return_Not_Found_When_Item_Does_Not_Exist()
        {
            // Arrange
            var itemToUpdate = TestFixture.Create <UpdateBeerContainer>();

            // Act
            var result = await _controller.PutAsync(itemToUpdate);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <NotFoundResult>();
        }
 public CreatePlannerItemCommandShould()
 {
     fixture = TestFixture.Create();
     fixture.Customize <PlannerItem>(c => c.Without(p => p.Category));
     item      = fixture.Create <PlannerItem>();
     itemModel = fixture.Create <PlannerItemModel>();
     mocker    = new AutoMoqer();
     mocker.GetMock <IMapper>()
     .Setup(m => m.Map <PlannerItemCreateEditModel, PlannerItem>(It.IsAny <PlannerItemCreateEditModel>()))
     .Returns(item);
     mocker.GetMock <IMapper>()
     .Setup(m => m.Map <PlannerItem, PlannerItemModel>(It.IsAny <PlannerItem>()))
     .Returns(itemModel);
     sut = mocker.Create <CreatePlannerItemCommand>();
 }
Exemplo n.º 22
0
        public async Task PutAsync_Should_Return_NotFound_When_Style_Does_Not_Exist()
        {
            // Arrange
            var updateRequest = TestFixture.Create <UpdateBeerStyle>();

            // Act
            var result = await _controller.PutAsync(updateRequest);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <NotFoundResult>();
        }
Exemplo n.º 23
0
 public SignInUserCommandShould()
 {
     fixture = TestFixture.Create();
     mocker  = new AutoMoqer();
     user    = new PlannerAppUser
     {
         Email    = EMAIL,
         TenantID = TENANTID
     };
     mocker.SetInstance <IConfiguration>(new ConfigurationMock());
     mocker.GetMock <IUserService>()
     .Setup(u => u.SignIn(It.IsAny <string>(), It.IsAny <string>()))
     .ReturnsAsync(user);
     sut = mocker.Create <SignInUserCommand>();
 }
Exemplo n.º 24
0
        public async Task Post_Should_Return_BadRequest_On_Exception()
        {
            // Arrange
            var addRequest = TestFixture.Create <CreateCellarItem>();

            _mockMapper.Setup(it => it.Map <CellarItem>(addRequest))
            .Throws <ArgumentException>();

            // Act
            var result = await _controller.Post(addRequest);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <BadRequestResult>();
        }
        public async Task Get_Should_Return_List_Of_Containers()
        {
            // Arrange
            var containers = TestFixture.Create <IEnumerable <BeerContainer> >();

            Context.BeerContainers.AddRange(containers);
            await Context.SaveChangesAsync();

            // Act
            var results = await _controller.GetAsync();

            // Assert
            results.Should()
            .NotBeNull();

            results.Should()
            .HaveCountGreaterThan(0);
        }
Exemplo n.º 26
0
        public async Task GetAsync_Should_Return_All_Styles()
        {
            // Arrange
            var styles = TestFixture.Create <IEnumerable <BeerStyle> >();
            await Context.BeerStyles.AddRangeAsync(styles);

            await Context.SaveChangesAsync();

            // Act
            var actualStyles = await _controller.GetAsync();

            // Assert
            actualStyles.Should()
            .NotBeNull();

            actualStyles.Should()
            .HaveCount(styles.Count());
        }
Exemplo n.º 27
0
        public async Task ShouldReturnTrueIfSessionWasUploaded()
        {
            // Arrange
            var fixture = new TestFixture <UploadPartCommandHandler>();
            var data    = new MemoryStream();
            var command = new UploadPartCommand(data, "1", "1");

            fixture.Freeze <ISessionsRepository>().FindNotCompletedSessionAsync(command.UploadId, CancellationToken.None)
            .Returns(fixture.Create <UploadSession>());

            fixture.Freeze <IBlobStorage>().UploadBlockBlob(data, "1", "1", CancellationToken.None).Returns(true);

            // Act
            var result = await fixture.Sut.Handle(command, CancellationToken.None);

            // Assert
            result.Should().BeTrue();
        }
Exemplo n.º 28
0
        public async Task PutAsync_Should_Update_Existing_Item()
        {
            // Arrange
            var updateRequest = TestFixture.Create <UpdateBeerStyle>();
            var itemToUpdate  = TestFixture.Build <BeerStyle>()
                                .With(_ => _.StyleId, updateRequest.StyleId)
                                .Create();

            await Context.BeerStyles.AddAsync(itemToUpdate);

            await Context.SaveChangesAsync();

            // Act
            var result = await _controller.PutAsync(updateRequest);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <OkObjectResult>();

            var returnedItem = ((result as OkObjectResult).Value as BeerStyle);

            returnedItem.Should()
            .NotBeNull();

            returnedItem.StyleId
            .Should()
            .Be(updateRequest.StyleId);

            returnedItem.StyleName
            .Should()
            .Be(updateRequest.StyleName);

            var dbItem = await Context.BeerStyles.FindAsync(updateRequest.StyleId);

            dbItem.Should()
            .NotBeNull();

            dbItem.StyleName
            .Should()
            .Be(updateRequest.StyleName);
        }
Exemplo n.º 29
0
        public async Task GetAsync_Should_Return_All_CellarItems()
        {
            // Arrange
            var items = TestFixture.Create <IEnumerable <CellarItem> >();

            await Context.CellarItems.AddRangeAsync(items);

            await Context.SaveChangesAsync();

            // Act
            var result = await _controller.GetAsync();

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .HaveCount(items.Count());
        }
Exemplo n.º 30
0
        public async Task PostAsync_Should_Return_BadRequest_On_Exception()
        {
            // Arrange
            var createRequest = TestFixture.Create <CreateBeerStyle>();

            _mockMapper.Setup(it => it.Map <BeerStyle>(createRequest))
            .Throws <ArgumentException>();

            // Act
            var result = await _controller.PostAsync(createRequest);

            // Assert
            TestMockRepository.VerifyAll();

            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <BadRequestResult>();
        }