示例#1
0
        public async Task CreateSessionAsync_NoRestrictions_ShouldReturnTheSession()
        {
            // Arrange
            context.Add(expectedSession);
            context.SaveChanges();

            //Act
            var actualSession = await repository.CreateSessionAsync(expectedUser);

            //Assert
            Assert.IsNotNull(actualSession);
            Assert.AreEqual(expectedUser.Id, actualSession.UserId);
        }
示例#2
0
        public async Task <Session> LoginAsync(LoginModel login)
        {
            login.Password = await encryptor.EncryptAsync(login.Password);

            var user = await repository.GetUserAsync(login);

            if (user == null)
            {
                throw new InvalidCredentialException("Invalid credentials");
            }
            var session = await repository.GetSessionAsync(user);

            if (session == null)
            {
                session = await repository.CreateSessionAsync(user);
            }
            return(session);
        }
        public async Task <StartUploadSessionResponse> Handle(StartUploadSessionCommand request, CancellationToken cancellationToken)
        {
            var sessionId = MongoDB.Bson.ObjectId.GenerateNewId().ToString();
            var entity    = new UploadSession
            {
                Id          = sessionId,
                FileName    = request.FileName,
                SizeInBytes = request.SizeInBytes,
                Parts       = GenerateUploadParts(request.SizeInBytes),
                Extension   = request.Extension
            };

            await _sessions.CreateSessionAsync(entity, cancellationToken);

            return(new StartUploadSessionResponse
            {
                Extension = request.Extension, Id = entity.Id, FileName = entity.FileName,
                SizeInBytes = entity.SizeInBytes, Parts = entity.Parts.ToList()
            });
        }