Exemplo n.º 1
0
 public CreateOrUpdateUserCommandHandlerTestsFixture()
 {
     Db = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
     CreateOrUpdateUserCommand = new CreateOrUpdateUserCommand(Guid.NewGuid(), "*****@*****.**", "Foo", "Bar");
     Handler = new CreateOrUpdateUserCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
     Now     = DateTime.UtcNow;
 }
        public void Handle(ClaimsIdentity claimsIdentity)
        {
            var @ref      = Guid.Parse(claimsIdentity.FindFirst(DasClaimTypes.Id).Value);
            var email     = claimsIdentity.FindFirst(DasClaimTypes.Email).Value;
            var firstName = claimsIdentity.FindFirst(DasClaimTypes.GivenName).Value;
            var lastName  = claimsIdentity.FindFirst(DasClaimTypes.FamilyName).Value;
            var command   = new CreateOrUpdateUserCommand(@ref, email, firstName, lastName);

            _unitOfWorkScope.RunAsync(c => c.GetInstance <IMediator>().Send(command)).GetAwaiter().GetResult();
        }
Exemplo n.º 3
0
        public async Task <CreateOrUpdateUserResult> CreateOrUpdateUserAsync(CreateOrUpdateUserCommand request)
        {
            bool profilePicHasChanged = true;
            bool nameHasChanged       = false;
            var  savedUser            = await FindUserEntityAsync(request.UserId);

            bool   isNewUser        = false;
            string originalUserName = null;

            if (savedUser != null)
            {
                originalUserName = savedUser.Entity.Name;

                profilePicHasChanged = savedUser.Entity.ProfileImageUrl != request.ProfileImageUrl;
                nameHasChanged       = savedUser.Entity.Name != request.Name;

                savedUser.Entity.LastOnline      = DateTime.UtcNow;
                savedUser.Entity.Name            = request.Name;
                savedUser.Entity.ProfileImageUrl = request.ProfileImageUrl;
                if (request.PushInfo != null && request.PushInfo.HasValue())
                {
                    savedUser.Entity.PushInfo = request.PushInfo;
                }

                if (request.Language != null)
                {
                    savedUser.Entity.Language = request.Language;
                }

                await this.storageAccessService.ReplaceAsync(TableNames.Users, savedUser);

                cacheService.Remove(GetUserCacheKey(request.UserId));
            }
            else
            {
                var user = new UserEntity()
                {
                    Id              = request.UserId,
                    Name            = request.Name,
                    Gender          = Gender.Male,
                    Language        = request.Language,
                    PushInfo        = request.PushInfo,
                    Weight          = 80,
                    LastOnline      = DateTime.UtcNow,
                    ProfileImageUrl = request.ProfileImageUrl
                };
                await this.storageAccessService.InsertAsync(TableNames.Users, new JsonTableEntity <UserEntity>(StaticPartitionKeys.User, request.UserId, user));

                isNewUser = true;
            }

            return(new CreateOrUpdateUserResult(isNewUser, profilePicHasChanged, nameHasChanged, originalUserName));
        }
Exemplo n.º 4
0
        public CreateOrUpdateUserCommandHandlerTestsFixture SetCommandWithChangedProperties()
        {
            CreateOrUpdateUserCommand = new CreateOrUpdateUserCommand(User.Ref, "_" + User.Email, "_" + User.FirstName, "_" + User.LastName);

            return(this);
        }