Esempio n. 1
0
            public async Task Should_return_status_code_201_for_the_created_weight_entry_Async()
            {
                //arrange
                //TODO: this will change with intro of mapper...

                var weight = RandomData.GetDecimal(0, int.MaxValue);
                var createWeightRequestDto = new CreateWeightRequestDto
                {
                    Weight = weight.ToString()
                };

                var newId = RandomData.GetAlphaString();

                _weightsService
                .Setup(s => s.AddWeightAsync(It.Is <CreateWeightRequest>(r => r.Weight == weight)))
                .ReturnsAsync(newId);

                //act
                //TODO: the Accept should not be necessary
                var response = await Browser.Post(RootUriStrings.Weights,
                                                  with => with.JsonBrowserContext(createWeightRequestDto)
                                                  .Accept("application/json"));

                //assert
                //TODO: assert on Location header
                //TODO: assert the Id is on the response body
                response.StatusCode
                .Should().Be(HttpStatusCode.Created);
            }
Esempio n. 2
0
 public ViewModelTests()
 {
     data = RandomData.GetAlphaString(1, 10);
     href = "/" + RandomData.GetAlphaString(1, 10);
     name = RandomData.GetAlphaString(1, 10);
     sut  = new ViewModel <string>(href);
 }
Esempio n. 3
0
 public ViewModelTests()
 {
     _data = RandomData.GetAlphaString(1, 10);
     _href = $"/{RandomData.GetAlphaString(1, 10)}";
     _name = RandomData.GetAlphaString(1, 10);
     _sut  = new ViewModel <string>(_href);
 }
 public static LogEvent Generate(string id = null, string companyId = null, string message = null, DateTime?createdUtc = null)
 {
     return(new LogEvent {
         Id = id,
         Message = message ?? RandomData.GetAlphaString(),
         CompanyId = companyId ?? ObjectId.GenerateNewId().ToString(),
         CreatedUtc = createdUtc ?? RandomData.GetDateTime(SystemClock.UtcNow.StartOfMonth(), SystemClock.UtcNow)
     });
 }
Esempio n. 5
0
        public void ConstructorShouldThrowAnArgumentNullExceptionWhenTheNameArgumentIsNull()
        {
            //ARRANGE
            var href = "/" + RandomData.GetAlphaString(1, 10);

            //ACT
            Action link = () => new Link(null, href);

            //ASSERT
            link.ShouldThrow <ArgumentNullException>();
        }
Esempio n. 6
0
        public void Constructor_ShouldThrowAnArgumentNullExceptionWhenTheHrefArgumentIsNull()
        {
            //ARRANGE
            var name = RandomData.GetAlphaString(1, 10);

            //ACT
            Action link = () => new Link(name, null);

            //ASSERT
            link.ShouldThrow <ArgumentNullException>();
        }
Esempio n. 7
0
 public static Employee Generate(string id = null, string name = null, int?age = null, string companyName = null, string companyId = null, DateTime?createdUtc = null, DateTime?updatedUtc = null)
 {
     return(new Employee {
         Id = id,
         Name = name ?? RandomData.GetAlphaString(),
         Age = age ?? RandomData.GetInt(18, 100),
         CompanyName = companyName ?? RandomData.GetAlphaString(),
         CompanyId = companyId ?? ObjectId.GenerateNewId().ToString(),
         CreatedUtc = createdUtc.GetValueOrDefault(),
         UpdatedUtc = updatedUtc.GetValueOrDefault()
     });
 }
Esempio n. 8
0
        public void AddErrorShouldThrowAnInvalidOperationExceptionWhenDataIsNotNull()
        {
            //ARRANGE
            var message = RandomData.GetAlphaString(1, 10);

            sut.Data = data;

            //ACT
            Action act = () => sut.AddError(message);

            //ASSERT
            act.ShouldThrow <InvalidOperationException>(Resources.ViewModelCannotAddError);
        }
Esempio n. 9
0
        public void DataShouldThrowAnInvalidOperationExceptionWhenSettingItToAnObjectAfterAnErrorWasAdded()
        {
            //ARRANGE
            var message = RandomData.GetAlphaString(1, 10);

            sut.AddError(message);

            //ACT
            Action act = () => sut.Data = data;

            //ASSERT
            act.ShouldThrow <InvalidOperationException>(Resources.ViewModelCannotSetDataProperty);
        }
Esempio n. 10
0
        public void AddLinkShouldAddEachLink()
        {
            //ARRANGE
            var secondName = RandomData.GetAlphaString(1, 10);
            var secondHref = "/" + RandomData.GetAlphaString(1, 10);

            //ACT
            sut.AddLink(name, href);
            sut.AddLink(secondName, secondHref);

            //ASSERT
            sut.Links.Count().ShouldBe(3); //The "self" link is added automatically when the view model is instantiated
            sut.Links.SingleOrDefault(x => x.Name == name && x.Href == href).ShouldNotBeNull();
            sut.Links.SingleOrDefault(x => x.Name == name && x.Href == href).ShouldNotBeNull();
        }
Esempio n. 11
0
        public static Employee GenerateRandom(string id = null, string name = null, int?age = null, int?yearsEmployed = null, string companyName = null, string companyId = null, string location = null, DateTime?lastReview = null, DateTimeOffset?nextReview = null, DateTime?createdUtc = null, DateTime?updatedUtc = null)
        {
            var employee = new Employee {
                Id            = id,
                Name          = name ?? RandomData.GetAlphaString(),
                Age           = age ?? RandomData.GetInt(18, 100),
                YearsEmployed = yearsEmployed ?? RandomData.GetInt(0, 40),
                CompanyName   = companyName ?? RandomData.GetAlphaString(),
                CompanyId     = companyId ?? ObjectId.GenerateNewId().ToString(),
                LastReview    = lastReview ?? RandomData.GetDateTime(DateTime.Now.SubtractDays(365), DateTime.Now),
                CreatedUtc    = createdUtc ?? RandomData.GetDateTime(DateTime.Now.SubtractDays(365), DateTime.Now),
                Location      = location ?? RandomData.GetCoordinate()
            };

            employee.NextReview = nextReview ?? RandomData.GetDateTimeOffset(employee.NextReview, DateTime.Now);
            employee.UpdatedUtc = updatedUtc ?? RandomData.GetDateTime(employee.CreatedUtc, DateTime.Now);

            return(employee);
        }
Esempio n. 12
0
        public void AddError_ShouldAddEachErrorWhenDataIsNull()
        {
            //ARRANGE
            var count    = RandomData.GetInt(2, 10);
            var messages = new string[count];

            //ACT
            for (var i = 0; i < count; i++)
            {
                messages[i] = RandomData.GetAlphaString(1, 10);

                _sut.AddError(messages[i], RandomData.GetInt(1, 10));
            }

            _sut.Errors.ShouldSatisfyAllConditions(
                () => _sut.Errors.Count().ShouldBe(count),
                () => _sut.Errors.Where(x => String.IsNullOrWhiteSpace(x.Message)).ShouldBeEmpty()
                );
        }
Esempio n. 13
0
        public void AddErrorShouldAddEachErrorWhenDataIsNull()
        {
            //ARRANGE
            var count    = RandomData.GetInt(2, 10);
            var messages = new String[count];

            //ACT
            for (var i = 0; i < count; i++)
            {
                messages[i] = RandomData.GetAlphaString(1, 10);

                sut.AddError(messages[i]);
            }

            //ASSERT
            sut.Errors.Count().ShouldBe(count);

            for (var i = 0; i < count; i++)
            {
                sut.Errors.SingleOrDefault(x => x.Message == messages[i]).ShouldNotBeNull();
            }
        }