示例#1
0
        public void TestCreateEntityViaDtoCtorCreateCtor1Ok()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <TestDbContext>();

            using (var context = new TestDbContext(options))
            {
                context.Database.EnsureCreated();
            }
            using (var context = new TestDbContext(options))
            {
                var utData  = context.SetupSingleDtoAndEntities <DtoCtorCreate>();
                var service = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var dto = new DtoCtorCreate {
                    MyInt = 123, MyString = "Hello"
                };
                service.CreateAndSave(dto, "ctor(1)");

                //VERIFY
                service.IsValid.ShouldBeTrue(service.GetAllErrors());
                service.Message.ShouldEqual("Successfully created a Ddd Ctor Entity");
            }
            using (var context = new TestDbContext(options))
            {
                context.DddCtorEntities.Count().ShouldEqual(1);
                context.DddCtorEntities.Find(1).MyInt.ShouldEqual(123);
                context.DddCtorEntities.Find(1).MyString.ShouldEqual("1 param ctor");
            }
        }
示例#2
0
        public void TestCreateEntityViaDtoCtorCreateCtorBad()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <TestDbContext>();

            using (var context = new TestDbContext(options))
            {
                var utData  = context.SetupSingleDtoAndEntities <DtoCtorCreate>();
                var service = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var dto = new DtoCtorCreate {
                    MyInt = 123, MyString = "Hello"
                };
                var ex = Assert.Throws <InvalidOperationException>(() => service.CreateAndSave(dto));

                //VERIFY
                ex.Message.ShouldStartWith("There are multiple ctor/static method, so you need to define which one you want used via the ctor/static method parameter. ");
            }
        }
        public void TestCreateEntityViaDtoCtorCreateCtorMatchesLongerOne()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <TestDbContext>();

            using (var context = new TestDbContext(options))
            {
                context.Database.EnsureCreated();

                var utData  = context.SetupSingleDtoAndEntities <DtoCtorCreate>();
                var service = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var dto = new DtoCtorCreate {
                    MyInt = 123, MyString = "Hello"
                };
                service.CreateAndSave(dto);

                //VERIFY
                context.DddCtorEntities.Single().MyInt.ShouldEqual(123);
                context.DddCtorEntities.Single().MyString.ShouldEqual("Hello");
            }
        }