public User CurrentUser()
        {
            var user = new User { Email = "*****@*****.**", Measurements = new List<Measurement>() };
            user.AddMeasurement(new Measurement { Time = DateTime.Now, Weight = 120 });
            user.AddMeasurement(new Measurement { Time = DateTime.Now.AddDays(-1), Weight = 119.5 });
            user.AddMeasurement(new Measurement { Time = DateTime.Now.AddDays(-2), Weight = 119.2 });

            return user;
        }
        public void Post_IfTargetUserAndCurrentUserDoesNotMatch_ThrowAccessDeniedError()
        {
            // Arrange.
            var user = new User {Email = "*****@*****.**"};
            _loginInformation.CurrentUser().Returns(user);
            var postData = new User {Email = "*****@*****.**"};

            // Act and assert.
            _controller
                .Invoking(c => c.Post(postData))
                .ShouldThrow<AccessDeniedException>("Restricted! You can only update your current account or add new nonexisting one.");
        }
        public void Get_IfLoggedIn_ReturnUserCorrectly()
        {
            // Arrange.
            var user = new User {Email = "*****@*****.**", Measurements = new List<Measurement>()};
            user.AddMeasurement(new Measurement {Time = DateTime.Now, Weight = 120});
            user.AddMeasurement(new Measurement { Time = DateTime.Now.AddDays(-1), Weight = 119.5 });
            user.AddMeasurement(new Measurement { Time = DateTime.Now.AddDays(-2), Weight = 119.2 });

            _loginInformation.CurrentUser().Returns(user);

            // Act and assert.
            _controller.Get().ShouldBeEquivalentTo(user);
        }
Example #4
0
        public void SaveOrUpdate_WorksCorrectly()
        {
            using (var session = _sessionFactory.OpenSession())
            {
                var measurements = new List<Measurement>
                {
                    new Measurement {Time = DateTime.Now, Weight = 100}
                };
                var user = new User {Email = "*****@*****.**", Measurements = measurements};

                session.SaveOrUpdate(user);
                var query = session.QueryOver<User>();

                var result = query.SingleOrDefault();
                result.Email.Should().Be("*****@*****.**");

                result.Measurements.ShouldAllBeEquivalentTo(measurements);
            }
        }