Beispiel #1
0
        public void AddUser_User_UserIsAdd()
        {
            // Method AddUser_User_UserIsAdd()
            // - AddUser: Name of the method being tested
            // - User: Scenario (state) under which the method is being tested
            // - UserIsAdd: Expected behavior when the scenario is invoked

            // ARRANGE
            // - Set up the context, instantiate the repository, create an user to add
            // ACT
            // - Call the AddUser method on the repository
            // ASSERT
            // - Check if user was added

            // ARRANGE
            PGContext  context = GetDbContext();
            UserEntity user    = new UserEntity(id: "0000", name: "TEST");

            // ACT
            EntityEntry <UserEntity> entry = context.Users.Add(entity: user);
            int numberOfStateEntries       = context.SaveChanges();

            // var entryEntity = context.Entry(entity: user);
            // entryEntity.State = EntityState.Added;

            // ASSERT
            Assert.AreEqual(expected: 1, actual: context.Users.Count());
        }
Beispiel #2
0
        public void TestGetingtData()
        {
            // ARRANGE
            PGContext context = GetDbContext();

            Seed(context: context);

            // ASSERT
            Assert.AreEqual(expected: 3, actual: context.Users.Count());
        }
Beispiel #3
0
        public PGContext GetDbContext()
        {
            PGContext context = serviceProvider.GetService <PGContext>();

            if (context is not null)
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
            }

            return(context);
        }
Beispiel #4
0
        private void Seed(PGContext context)
        {
            List <UserEntity> userLst = new()
            {
                new UserEntity(id: "0000", name: "TEST"),
                new UserEntity(id: "0001", name: "TEST"),
                new UserEntity(id: "0002", name: "TEST")
            };

            context.Users.AddRange(entities: userLst);
            context.SaveChanges();
        }
Beispiel #5
0
 public PGRepository(PGContext pGContext)
 {
     this.PGContext = pGContext;
 }