Exemple #1
0
        public async Task <ActionResult <ExampleEntity> > Add(ExampleEntity entitiy)
        {
            _context.Add(entitiy);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetExampleEntityById), new { id = entitiy.ExampleId }, entitiy));
        }
Exemple #2
0
 public IActionResult addSample(SampleModel newSample)
 {
     // sanity check
     // if(newSample.sampleBucketID > 0)
     // {
     //     _context.Add(newSample);
     //     _context.SaveChanges();
     //     return Content($"Added Sample {newSample.id} with Bucket {newSample.sampleBucketID}");
     // } else
     // {
     //     return Content($"bucket dropdown error");
     // }
     _context.Add(newSample);
     _context.SaveChanges();
     return(RedirectToAction("listAll"));
 }
Exemple #3
0
        public async Task <ActionResult <Person> > PostPerson(Person person)
        {
            _context.Add <Person>(person);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetPerson), new { person.Id }, person));
        }
Exemple #4
0
        public TodoItem BizAction(CreateTodoDto inputData)
        {
            if (inputData.Name.EndsWith("!"))
            {
                AddError("Business logic says the name cannot end with !", nameof(inputData.Name));
            }

            var item = new TodoItem(inputData.Name, inputData.Difficulty);

            _context.Add(item);

            Message = $"Successfully saved the todo item '{inputData.Name}'.";
            return(item);
        }
        protected virtual Guid SaveIt()
        {
            using (var dbContext = new ExampleDbContext(_dbContextOptions))
            {
                var newThing = new EfcThing
                {
                    Value = 45.0
                };
                dbContext.Add(newThing);
                dbContext.SaveChanges();

                return(newThing.Id);
            }
        }
Exemple #6
0
        public async Task TestCheckSaveChangesAsyncReturningCount()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

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

                //ATTEMPT
                context.Add(new TaxRate(DateTime.UtcNow, 4));
                var numUpdates = await context.SaveChangesAsync();

                //VERIFY
                numUpdates.ShouldEqual(1);
            }
        }
Exemple #7
0
        public DatabaseFixture()
        {
            // establish an in-memory database
            var dbOptions = new DbContextOptionsBuilder <ExampleDbContext>()
                            .UseInMemoryDatabase(databaseName: "exampleapi")
                            .Options;

            mockExampleDbContext  = new ExampleDbContext(dbOptions);
            this.personController = new PersonController(mockExampleDbContext);

            // seed database with randomly generated test persons
            mockExampleDbContext.Database.EnsureCreated();
            for (int i = 0; i < 10; i++)
            {
                testPersons[i] = CreateRandomPerson();
                mockExampleDbContext.Add(testPersons[i]);
            }
            mockExampleDbContext.SaveChanges();
        }
        public void TestChangeDifficultyOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

            using (var context = new ExampleDbContext(options))
            {
                context.Database.EnsureCreated();
                context.Add(new TodoItem("Test", 1));
                context.SaveChanges();

                //ATTEMPT
                var item = context.TodoItems.Single();
                item.ChangeDifficulty(2);
                context.SaveChanges();

                //VERIFY
                context.TodoItems.Single().Difficulty.ShouldEqual(2);
            }
        }
        public void TestChangeNameWithErrorOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

            using (var context = new ExampleDbContext(options))
            {
                context.Database.EnsureCreated();
                context.Add(new TodoItem("Test", 1));
                context.SaveChanges();

                //ATTEMPT
                var item   = context.TodoItems.Single();
                var status = item.ChangeName("New Name!");

                //VERIFY
                status.IsValid.ShouldBeFalse(status.GetAllErrors());
                status.GetAllErrors().ShouldEqual("Business logic says the name canot end with !");
            }
        }