Code Monkey home page Code Monkey logo

reseed's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

reseed's Issues

Reseed not properly deleting data from database after a test

With reseed and xunit the data inserted in the prepare database phase and data inserted during tests are not being deleted from the database when cleanup database is called at the end of the test. The record created during prepare database is not removed from the database after cleanup is called. If I call restore database in the dispose method the records are properly deleted after tests.

SeedActions

        {
            var deviceLogTable = new ObjectName("DeviceActivityLog");
            string deviceQuery = $"DELETE FROM [dbo].[DeviceActivityLog] where DeviceId = {TestData.DeviceId.ToString()}";

            var actions = _reseeder.Generate(
                dbConnection, SeedMode.Basic(
                    BasicInsertDefinition.Script(),
                    CleanupDefinition.Script(
                        CleanupMode.Delete(),
                        CleanupTarget.Including(
                            configure: c => c.IncludeTables(new ObjectName("DeviceActivityLog")),
                            customScripts: new[]
                            {
                                (deviceLogTable, deviceQuery)

                            }
                            
                        )),
                    DataProviders.Inline(builder => builder


                         //Add barcode
                         .AddEntities(
                            new Entity("DeviceActivityLog",
                            new[]
                            {
                                new Property("DeviceActivityLogId",TestData.DeviceActivityLogId.ToString()),
                                new Property("ActivityUnique",TestData.DeviceActivityUnique.ToString()),
                                new Property("Timestamp","2022-05-31 19:56:39.000"),
                                new Property("DeviceActivityTypeId","23"),
                                new Property("EntityId",TestData.LocationId.ToString()),
                                new Property("DeviceId",TestData.DeviceId.ToString()),
                                new Property("TransAmount","0.00"),
                                new Property("TicketPrice","0.00"),
                                new Property("ActivityLogFileName","220531195639"),
                                new Property("IsError","1"),
                                new Property("DrawerNumber",""),
                                new Property("ErrorMessage",""),
                            }
                          ))

                         .Build())));
            return actions;
        }

Base test class. Constructor gets called before each test where I call Restore Database.


[Collection("Database Collection")]
    public class BaseApiTest
    {
        protected readonly TestFixture fixture;
        protected readonly ITestOutputHelper testOutput;
        public DatabaseHelper databaseHelper;
        


        //constructor is called before each test
        public BaseApiTest(TestFixture _fixture, ITestOutputHelper testOutputHelper)
        {
            fixture = _fixture;
            testOutput = testOutputHelper;

            fixture.Databases.ForEach(db => db.RestoreDatabase());

        }



        //Returns authenticated HTTP client with  bearer token
        public HttpClient GetClient()
        {
            var client = fixture.Client;

            return client;
        }
    }

Test Fixture where I can Cleanup Database in dispose which is called after all tests have run.



public TestFixture()
        {
            Client = new HttpClient();

            TmsConnection = new SqlConnection(TmsConnectionString);
            TmsConnection.Open();
            DbTMS = new DatabaseHelperTMS(TmsConnection);

            LoggingConnection = new SqlConnection(LoggingConnectionString);
            LoggingConnection.Open();
            DbLogging = new DatabaseHelperLogging(LoggingConnection);
            
            Databases = new List<IDatabaseSeedManager>() { DbTMS, DbLogging };
            Databases.ForEach(db => db.PrepareDatabaseSeed());
        }


        //runs after class is created before any tests run
        //Get bearer token to authenticate client
        public async Task InitializeAsync()
        {
            await AuthenticateClient();
            
        }


        public async Task DisposeAsync()
        {
            
        }


        public void Dispose()
        {
            Databases.ForEach(db => db.CleanDatabase());
        }


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.