public void DeserializesSomeFromNumber()
        {
            const string json            = @"42";
            const int    expectedInteger = 42;

            FunctionalAssert.IsSome(expectedInteger, JsonConvert.DeserializeObject <Option <int> >(json, Settings));
        }
        public void DeserializesSomeFromObject()
        {
            const string json           = @"{""FirstName"":""Peter"",""LastName"":""Pan""}";
            var          expectedObject = new Person("Peter", "Pan");

            FunctionalAssert.IsSome(expectedObject, JsonConvert.DeserializeObject <Option <Person> >(json, Settings));
        }
        public void ResolvingAnOptionWhenTypeIsNotRegisteredReturnsNone()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterOption();
            using var container = containerBuilder.Build();
            FunctionalAssert.IsNone(container.Resolve <Option <ILogger> >());
        }
        public void ResolvingAnOptionWhenTypeIsRegisteredReturnsInstance()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterOption();
            containerBuilder.RegisterType <NullLogger>().AsImplementedInterfaces();
            using var container = containerBuilder.Build();
            var logger = FunctionalAssert.IsSome(container.Resolve <Option <ILogger> >());

            Assert.True(logger is NullLogger);
        }
        public void ResolvingAnOptionWhenMultipleTypesForSameServiceAreRegisteredReturnsDefaultService()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterOption();
            containerBuilder.RegisterType <NullLogger>().AsImplementedInterfaces();
            containerBuilder.RegisterType <StandardOutputLogger>().AsImplementedInterfaces();
            using var container = containerBuilder.Build();
            var logger = FunctionalAssert.IsSome(container.Resolve <Option <ILogger> >());

            Assert.True(logger is StandardOutputLogger);
        }
Пример #6
0
        public async Task ReturnsSomeWhenOneEntityIsFound()
        {
            using var db = new TestContext();

            var insertedPerson = new Person {
                FirstName = "Jane", LastName = "Doe"
            };
            await db.People.AddAsync(insertedPerson);

            await db.SaveChangesAsync();

            var person = FunctionalAssert.IsSome(await db.People.SingleOrNoneAsync());

            Assert.Equal(insertedPerson.Id, person.Id);
        }
Пример #7
0
        public async Task ReturnsSomeWhenAMatchingEntityIsFound()
        {
            using var db = new TestContext();

            var insertedPerson1 = new Person {
                FirstName = "Jane", LastName = "Doe"
            };
            await db.People.AddAsync(insertedPerson1);

            var insertedPerson2 = new Person {
                FirstName = "Peter", LastName = "Example"
            };
            await db.People.AddAsync(insertedPerson2);

            await db.SaveChangesAsync();

            var person = FunctionalAssert.IsSome(await db.People.SingleOrNoneAsync(p => p.FirstName == "Jane"));

            Assert.Equal(insertedPerson1.Id, person.Id);
        }
        public async Task ReturnsTheFirstMatchingEntity()
        {
            using var db = new TestContext();

            var insertedPerson1 = new Person {
                FirstName = "Jane", LastName = "Doe"
            };
            await db.People.AddAsync(insertedPerson1);

            var insertedPerson2 = new Person {
                FirstName = "Peter", LastName = "Example"
            };
            await db.People.AddAsync(insertedPerson2);

            await db.SaveChangesAsync();

            var person = FunctionalAssert.IsSome(await db.People.OrderByDescending(p => p.LastName).FirstOrNoneAsync());

            Assert.Equal(insertedPerson2.Id, person.Id);
        }
Пример #9
0
 public async Task ReturnsNoneWhenNoMatchingEntitiesAreFound()
 {
     using var db = new TestContext();
     FunctionalAssert.IsNone(await db.People.SingleOrNoneAsync());
 }
        public void DeserializesNoneFromNull()
        {
            const string json = @"null";

            FunctionalAssert.IsNone(JsonConvert.DeserializeObject <Option <string> >(json, Settings));
        }