urfnet / URF.Core

Unit of Work & Repositories Framework - .NET Core, NET Standard, Entity Framework Core. 100% extensible & lightweight.
https://github.com/urfnet
MIT License
309 stars 62 forks source link

Post example not working #15

Closed Domitnator closed 6 years ago

Domitnator commented 6 years ago

Hi Guys,

First of all: Thanks for bringing URF to .net core! I liked working with the "old" urf framework a lot!

I am wondering if the Post action in the ODataController is actually working?

image

I created my own project and basically did the same implementation as the sample project but no record is inserted into the (sql server) database eventually.

To make sure it is not a bug i created myself i cloned the sample project (https://github.com/urfnet/URF.Core.Sample) and runned the sample application (and sample api). And again, no record is inserted into the database. I also noticed that there are no unit/integration tests for adding a record to the database via the a service. All the existing service tests are for getting the data (which works perfectly).

Then i cloned the whole urf.core project and created some new tests:

1: Add a ProductLicense (just a simple class) via the repository and save changes:

image

Which works totally fine. A record is inserted into the database.

  1. Add a ProductLicense via the service and then save changes:

image

Which is failing because no record is inserted into the datbase.

But i cannot believe this is an error in the framework. Otherwise other people would have run into this issue too.

But from what i can see is that the Insert is not setting the TrackingState to "added". I says it is "unchanged"

image

Am i the only one who is having troubles with this? I am using .Net core 2.1.4 and .net standard 2.0 and sql server 2016.

Domitnator commented 6 years ago

To make things easier/debugable:

You can simply add this test to \URF.Core\URF.Core.EF.Tests\ServiceTest.cs. Where i simply try to add a customer by using the service.

   [Fact]
        public async Task InsertCustomer_Should_add_record_to_the_database()
        {
            IUnitOfWork unitOfWork = new UnitOfWork(_fixture.Context);
            ITrackableRepository<Customer> customerRepository = new TrackableRepository<Customer>(_fixture.Context);
            ITrackableRepository<Order> orderRepository = new TrackableRepository<Order>(_fixture.Context);
            var customerService = new CustomerService(customerRepository, orderRepository);

            var cust = new Customer {
                CustomerId = "COMP1",
                CompanyName = "Company 1"
            };

            customerService.Insert(cust);

            Assert.Equal(TrackableEntities.Common.Core.TrackingState.Added, cust.TrackingState);

            var savedChanges = await unitOfWork.SaveChangesAsync();

            Assert.Equal<int>(1, savedChanges);
        }

And see that nothing is being added to the database.

lelong37 commented 6 years ago

Hi @Domitnator, could you be so kind and please go ahead and issue a PR (Pull Request) and submit your failing unit test so that we can debug this as well? We'll probably accept your PR and unit test and go ahead make it part of our actual unit test suite.

Domitnator commented 6 years ago

@lelong37 : Sure! Will do this tommorow!

lelong37 commented 6 years ago

Could you guys @Domitnator @sreul be so kind to test, again, just released v1.0.0beta2 https://github.com/urfnet/URF.Core/releases/tag/1.0.0-beta2. Sample https://github.com/urfnet/URF.Core.Sample has also been updated w/ fix.

@Domitnator please still issue your PR w/ failing unit test, which should be passing now, if you update your NuGet packages https://www.nuget.org/packages?q=urf.core to latest beta2 bits. We've temporarily added your unit test, however would like your PR still so we can track as well as giving you credit for the PR. :) Nevermind, just saw your PR https://github.com/urfnet/URF.Core/pull/16 and accepted and merged: https://github.com/urfnet/URF.Core/commit/96b04ef9a515af05b84b84993d21ae3b0898fe59, thanks @Domitnator!

Domitnator commented 6 years ago

@lelong37 : Just confirmed it now works, great work! Case closed! Kind Regards, Alfred