public void UserIdIsRequired()
        {
            var command = new CreateWorkoutCommand(Guid.Empty);
            var handle = new CreateWorkoutCommandHandler(null, null);

            Assert.Throws<ApplicationException>(() => handle.Handle(command));
        }
        public void WorkoutIsSentToTheDatabase()
        {
            var id = Guid.NewGuid();
            var command = new CreateWorkoutCommand(id);
            var repo = Substitute.For<Core.DataAbstractions.IRepository<Workout>>();
            var session = Substitute.For<ISessionStorage>();
            var handle = new CreateWorkoutCommandHandler(repo, session);

            handle.Handle(command);

            repo.Received(1).Add(Arg.Is<Workout>(w => w.UserId == id));
        }
Esempio n. 3
0
        public Workout CurrentWorkout()
        {
            var userData = _sessionStorage.UserData;

            if (userData == null) return null;

            var query = new OpenWorkoutForUserQuery(userData.UserInfo.Id);
            var result = _repository.Single(query);

            if (result == null)
            {
                var command = new CreateWorkoutCommand(userData.UserInfo.Id);
                result = _commandInvoker.ExecuteResult<CreateWorkoutCommand, Workout>(command);
            }

            return result;
        }