Exemplo n.º 1
0
            private IMembershipService GetMembershipService()
            {
                var roles = GetDummyRoles(new[] {
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
                });
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetRole(
                                     It.Is <string>(name =>
                                                    roles.Any(
                                                        role => role.Name.Equals(
                                                            name, StringComparison.OrdinalIgnoreCase
                                                            )
                                                        )
                                                    )
                                     )
                                 ).Returns <string>(name =>
                                                    roles.FirstOrDefault(
                                                        role => role.Name.Equals(
                                                            name, StringComparison.OrdinalIgnoreCase
                                                            )
                                                        )
                                                    );

                return(mockMemSrv.Object);
            }
            private static ContainerBuilder GetInitialContainerbuilder()
            {
                var builder    = IntegrationTestHelper.GetEmptyContainerBuilder();
                var mockMemSrv = ServicesMockHelper.GetInitialMembershipServiceMock();

                builder.Register(c => mockMemSrv.Object).As <IMembershipService>().InstancePerRequest();
                return(builder);
            }
Exemplo n.º 3
0
            private static IMembershipService GetMembershipService()
            {
                CryptoService cryptoService = new CryptoService();
                var           salt          = cryptoService.GenerateSalt();

                var users = GetDummyUsers(new[] {
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
                });
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.CreateUser(
                                     It.IsAny <string>(), It.IsAny <string>(),
                                     It.IsAny <string>(), It.IsAny <string[]>()
                                     )
                                 ).Returns <string, string, string, string[]>(
                    (username, email, password, roles) =>

                    new OperationResult <UserWithRoles>(true)
                {
                    Entity = new UserWithRoles {
                        User = new User {
                            Key            = Guid.NewGuid(),
                            Name           = username,
                            Email          = email,
                            Salt           = salt,
                            HashedPassword = cryptoService.EncryptPassword(password, salt),
                            CreatedOn      = DateTime.Now,
                            IsLocked       = false
                        },
                        Roles = roles.Select(
                            roleName => new Role {
                            Key  = Guid.NewGuid(),
                            Name = roleName
                        }
                            )
                    }
                }
                    );

                mockMemSrv.Setup(ms => ms.CreateUser(
                                     It.Is <string>(
                                         userName =>
                                         users.Any(x =>
                                                   x.User.Name.Equals(
                                                       userName, StringComparison.OrdinalIgnoreCase
                                                       )
                                                   )
                                         ),
                                     It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string[]>()
                                     )
                                 ).Returns(new OperationResult <UserWithRoles>(false));

                return(mockMemSrv.Object);
            }
Exemplo n.º 4
0
            private IMembershipService GetMembershipService()
            {
                var roles = GetDummyRoles(new[] {
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
                });
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetRoles()).Returns(roles);

                return(mockMemSrv.Object);
            }
        Returns_200_And_Expected_User_For_The_Authed_User()
        {
            // Arrange
            var mockMemSrv = ServicesMockHelper
                             .GetInitialMembershipServiceMock();

            mockMemSrv.Setup(ms =>
                             ms.GetUser(Constants.ValidAffiliateUserName)
                             ).Returns <string>(
                userName => new UserWithRoles {
                User = new User {
                    Key           = Guid.NewGuid(),
                    Name          = userName,
                    Email         = "*****@*****.**",
                    IsLocked      = false,
                    CreatedOn     = DateTime.Now.AddDays(-10),
                    LastUpdatedOn = DateTime.Now.AddDays(-5)
                },
                Roles = new List <Role> {
                    new Role {
                        Key = Guid.NewGuid(), Name = "Affiliate"
                    }
                }
            }
                );

            var config = IntegrationTestHelper
                         .GetInitialIntegrationTestConfig(
                GetInitialServices(mockMemSrv.Object));

            var request = HttpRequestMessageHelper
                          .ConstructRequest(
                httpMethod: HttpMethod.Get,
                uri: string.Format(
                    "https://localhost/{0}", "api/auth"),
                mediaType: "application/json",
                username: Constants.ValidAffiliateUserName,
                password: Constants.ValidAffiliatePassword);

            // Act
            var user = await IntegrationTestHelper.GetResponseMessageBodyAsync <UserDto>(config, request, HttpStatusCode.OK);

            // Assert
            Assert.Equal(Constants.ValidAffiliateUserName, user.Name);
            Assert.True(user.Roles.Any(
                            role => role.Name.Equals(
                                "Affiliate",
                                StringComparison.OrdinalIgnoreCase
                                )
                            )
                        );
        }
Exemplo n.º 6
0
            private static IMembershipService GetMembershipService()
            {
                var users = GetDummyUsers(new[] {
                    Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
                });
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetUsers(
                                     It.IsAny <int>(), It.IsAny <int>()
                                     )
                                 ).Returns <int, int>((page, take) =>
                                                      users.AsQueryable()
                                                      .ToPaginatedList(page, take)
                                                      );

                return(mockMemSrv.Object);
            }
Exemplo n.º 7
0
            private IMembershipService GetMembershipService(Guid[] keys)
            {
                var roles      = GetDummyRoles(keys);
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetRole(
                                     It.Is <Guid>(key =>
                                                  keys.Contains(key)
                                                  )
                                     )
                                 ).Returns <Guid>(key =>
                                                  roles.FirstOrDefault(
                                                      role => role.Key == key
                                                      )
                                                  );

                return(mockMemSrv.Object);
            }
Exemplo n.º 8
0
            private static IMembershipService GetMembershipService(Guid[] keys)
            {
                var users      = GetDummyUsers(keys);
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetUser(
                                     It.Is <Guid>(
                                         key => keys.Contains(key)
                                         )
                                     )
                                 ).Returns <Guid>(key =>
                                                  users.FirstOrDefault(x =>
                                                                       x.User.Key == key
                                                                       )
                                                  );

                return(mockMemSrv.Object);
            }
Exemplo n.º 9
0
            private static IMembershipService GetMembershipService(Guid[] keys)
            {
                var users      = GetDummyUsers(keys);
                var mockMemSrv = ServicesMockHelper
                                 .GetInitialMembershipServiceMock();

                mockMemSrv.Setup(ms => ms.GetUser(
                                     It.Is <Guid>(
                                         key => keys.Contains(key)
                                         )
                                     )
                                 ).Returns <Guid>(key =>
                                                  users.FirstOrDefault(x =>
                                                                       x.User.Key == key
                                                                       )
                                                  );

                mockMemSrv.Setup(ms => ms.UpdateUser(
                                     It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>()
                                     )
                                 ).Returns <User, string, string>(
                    (user, username, email) => {
                    var roles = users
                                .FirstOrDefault(
                        x => x.User.Name.Equals(user.Name, StringComparison.OrdinalIgnoreCase)).Roles;

                    user.Name  = username;
                    user.Email = email;
                    return(new UserWithRoles {
                        User = user,
                        Roles = roles
                    });
                }
                    );

                return(mockMemSrv.Object);
            }