예제 #1
0
        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;
        }
예제 #2
0
        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.");
        }
예제 #3
0
        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);
        }
예제 #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);
            }
        }