Ejemplo n.º 1
0
        public async Task Edit_Inexistent_User_WithValidInput_ShouldReturn_RestException()
        {
            var mockedContext            = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var mockedHasher             = new Mock <IPasswordHasher>();
            var mockedCurrentUserAcessor = new Mock <ICurrentUserAccessor>();

            mockedCurrentUserAcessor.Setup(mcua => mcua.GetCurrentUsername()).Returns("test");
            var mockedMapper = new Mock <IMapper>();

            var sut = new Edit.Handler(mockedContext, mockedHasher.Object, mockedCurrentUserAcessor.Object, mockedMapper.Object);

            var message = new Edit.Command
            {
                User = new Edit.UserData
                {
                    Username = "******",
                    Bio      = "some bio",
                    Email    = "*****@*****.**",
                    Password = "******"
                }
            };

            var result = await sut.Handle(message, CancellationToken.None);

            Assert.Null(result.User);
        }
Ejemplo n.º 2
0
        public async Task Create_Project_LoggedWithValidInput_Should_CreateProject()
        {
            var fixture                  = new Fixture();
            var mockedContext            = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var mockedCurrentUserAcessor = new Mock <ICurrentUserAccessor>();

            mockedCurrentUserAcessor.Setup(mcua => mcua.GetCurrentUsername()).Returns("test");

            var sut = new Create.Handler(mockedContext, mockedCurrentUserAcessor.Object);

            var compentlist = fixture.Create <string[]>();
            var taglist     = fixture.Create <string[]>();

            var message = new Create.Command
            {
                Project = new Create.ProjectData
                {
                    ComponentList = compentlist,
                    Title         = "Title",
                    Description   = "Description",
                    Body          = "Body",
                    TagList       = taglist
                }
            };

            var result = await sut.Handle(message, CancellationToken.None);

            Assert.Equal(result.Project.Title, message.Project.Title);
        }
Ejemplo n.º 3
0
        public async Task Create_Project_NotLogged_WithValidInput_ShouldReturn_InvalidOperationException()
        {
            var fixture                  = new Fixture();
            var mockedContext            = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var mockedCurrentUserAcessor = new Mock <ICurrentUserAccessor>();

            var sut = new Create.Handler(mockedContext, mockedCurrentUserAcessor.Object);

            var compentlist = fixture.Create <string[]>();
            var taglist     = fixture.Create <string[]>();

            var message = new Create.Command
            {
                Project = new Create.ProjectData
                {
                    ComponentList = compentlist,
                    Title         = "Title",
                    Description   = "Description",
                    Body          = "Body",
                    TagList       = taglist
                }
            };

            await Assert.ThrowsAsync <InvalidOperationException>(() => sut.Handle(message, CancellationToken.None));
        }
Ejemplo n.º 4
0
        public async Task Create_Component_LoggedWithValidInput_Should_CreateComponent()
        {
            var fixture                  = new Fixture();
            var mockedContext            = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var mockedCurrentUserAcessor = new Mock <ICurrentUserAccessor>();

            mockedCurrentUserAcessor.Setup(mcua => mcua.GetCurrentUsername()).Returns("test");

            var sut = new Create.Handler(mockedContext, mockedCurrentUserAcessor.Object);

            var wheretofinditlist = fixture.Create <string[]>();

            var message = new Create.Command
            {
                Component = new Create.ComponentData()
                {
                    Name              = "Component",
                    Description       = "Description",
                    WhereToFindItList = wheretofinditlist
                }
            };

            var result = await sut.Handle(message, CancellationToken.None);

            Assert.Equal(result.Component.Description, message.Component.Description);
        }
Ejemplo n.º 5
0
        public async Task Get_Component_Inexistent_ShouldReturn_RestException()
        {
            var mockedContext = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var sut           = new Details.QueryHandler(mockedContext);
            var message       = new Details.Query("slug");

            await Assert.ThrowsAsync <RestException>(() => sut.Handle(message, CancellationToken.None));
        }
Ejemplo n.º 6
0
        public async Task Get_Tags_Inexistent_ShouldReturn_NoTags()
        {
            var mockedContext = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var sut           = new List.QueryHandler(mockedContext);
            var message       = new List.Query();

            var result = await sut.Handle(message, CancellationToken.None);

            Assert.Empty(result.Tags);
        }
Ejemplo n.º 7
0
        public async Task Delete_Favorite_Inexistent_ShouldReturn_RestException()
        {
            var mockedContext            = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var mockedCurrentUserAcessor = new Mock <ICurrentUserAccessor>();

            mockedCurrentUserAcessor.Setup(mcua => mcua.GetCurrentUsername()).Returns("test");
            var sut     = new Delete.QueryHandler(mockedContext, mockedCurrentUserAcessor.Object);
            var message = new Delete.Command("slug");

            await Assert.ThrowsAsync <RestException>(() => sut.Handle(message, CancellationToken.None));
        }
Ejemplo n.º 8
0
 public async Task Get_User_Inexistent_ShouldReturn_RestException()
 {
     var mockedContext = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
     var mockedMapper  = new Mock <IMapper>();
     var sut           = new Details.QueryHandler(mockedContext, mockedMapper.Object);
     var message       = new Details.Query
     {
         Username = "******"
     };
     await Assert.ThrowsAsync <RestException>(() => sut.Handle(message, CancellationToken.None));
 }
Ejemplo n.º 9
0
        public async Task Add_Favorite_NotLogged_WithValidInput_ShouldReturn_RestException()
        {
            var mockedContext            = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var mockedCurrentUserAcessor = new Mock <ICurrentUserAccessor>();

            var sut = new Add.QueryHandler(mockedContext, mockedCurrentUserAcessor.Object);

            var message = new Add.Command("slug");

            await Assert.ThrowsAsync <RestException>(() => sut.Handle(message, CancellationToken.None));
        }
Ejemplo n.º 10
0
        public async Task Get_Components_Inexistent_ShouldReturn_ZeroComponents()
        {
            var mockedCurrentUserAcessor = new Mock <ICurrentUserAccessor>();

            mockedCurrentUserAcessor.Setup(mcua => mcua.GetCurrentUsername()).Returns("test");
            var mockedContext = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var sut           = new List.QueryHandler(mockedContext, mockedCurrentUserAcessor.Object);
            var message       = new List.Query(String.Empty, String.Empty, "searchTerm", limit: 10, offset: 0);

            var result = await sut.Handle(message, CancellationToken.None);

            Assert.Equal(0, result.ComponentsCount);
        }
Ejemplo n.º 11
0
        public async Task Edit_Inexistent_Project_WithValidInput_ShouldReturn_RestException()
        {
            var mockedContext = new EletronicPartsCatalogContextMock().GetMockedContextWithData();

            var sut = new Edit.Handler(mockedContext);

            var message = new Edit.Command
            {
                Component = new Edit.ComponentData()
                {
                    Description = "Description",
                },
                Slug = "slug"
            };

            await Assert.ThrowsAsync <RestException>(() => sut.Handle(message, CancellationToken.None));
        }
Ejemplo n.º 12
0
        public async Task Create_Comment_NotLogged_WithValidInput_ShouldReturn_InvalidOperationException()
        {
            var mockedContext            = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var mockedCurrentUserAcessor = new Mock <ICurrentUserAccessor>();

            var sut = new Create.Handler(mockedContext, mockedCurrentUserAcessor.Object);

            var message = new Create.Command
            {
                Comment = new Create.CommentData()
                {
                    Body = "Body"
                }
            };

            await Assert.ThrowsAsync <RestException>(() => sut.Handle(message, CancellationToken.None));
        }
Ejemplo n.º 13
0
        public async Task Create_User_WithInvalidInput_ShouldReturn_InvalidOperationException()
        {
            var mockedContext           = new EletronicPartsCatalogContextMock().GetMockedContextWithData();
            var mockedHasher            = new Mock <IPasswordHasher>();
            var mockedJwtTokenGenerator = new Mock <IJwtTokenGenerator>();
            var mockedMapper            = new Mock <IMapper>();
            var sut = new Create.Handler(mockedContext, mockedHasher.Object, mockedJwtTokenGenerator.Object, mockedMapper.Object);

            var message = new Create.Command
            {
                User = new Create.UserData()
                {
                    Username             = "******",
                    Email                = "*****@*****.**",
                    Password             = "******",
                    PasswordConfirmation = "another pass"
                }
            };

            await Assert.ThrowsAsync <NullReferenceException>(() => sut.Handle(message, CancellationToken.None));
        }