예제 #1
0
        public void GoalRepository()
        {
            Mock <IDbSetFactory> factory = new Mock <IDbSetFactory>();
            Mock <DbSet <Goal> > dbSet   = new Mock <DbSet <Goal> >();

            factory.Setup(m => m.CreateDbSet <Goal>()).Returns(dbSet.Object);

            GoalRepository repo = new GoalRepository(factory.Object);

            var Goal = new Goal();

            var sequence = new MockSequence();

            dbSet.InSequence(sequence).Setup(e => e.Add(Goal));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            repo.Create(Goal);
            repo.Get(Goal.Id);
            repo.Update(Goal);
            repo.Delete(Goal.Id);
        }
예제 #2
0
        public void CreateUpdateDeleteFetch()
        {
            // file system
            var path         = "/shop/randomsilo/modern-web/backends/GoalTracker";
            var project      = "GoalTracker";
            var outputPath   = $"{path}/{project}.Infrastructure.Test/TestOutput/";
            var databaseFile = GetDatabase(outputPath, MethodBase.GetCurrentMethod());

            // logger
            ILogger logger = GetLogger($"{outputPath}/{MethodBase.GetCurrentMethod().ReflectedType.Name}_{MethodBase.GetCurrentMethod().Name}.log");

            // database setup

            // - context
            IDatabaseContext databaseContext = new DatabaseContext(
                $"Data Source={databaseFile}"
                , "TestDb"
                , "TestSchema"
                , $"{path}/sql/sqlite/ALL.sql"
                );

            Assert.NotNull(databaseContext);

            // - manager
            IManageDatabase databaseManager = new DatabaseManager(databaseContext);

            Assert.NotNull(databaseManager);

            // - create tables
            databaseManager.CreateDatabase();

            // - repository
            var goalRepository = new GoalRepository(databaseManager, new GoalRepositorySql(), logger);

            Assert.NotNull(goalRepository);

            // faker
            BrashActionResult <Goal> result = null;
            var goalFaker = new GoalFaker(databaseManager, logger);

            Assert.NotNull(goalFaker);

            // create
            var goalCreateModel = goalFaker.GetOne();

            result = goalRepository.Create(goalCreateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
            Assert.True(result.Model.GoalId > 0);

            // use model with id
            goalCreateModel = result.Model;

            // update
            var goalUpdateModel = goalFaker.GetOne();

            goalUpdateModel.GoalId = goalCreateModel.GoalId;
            result = goalRepository.Update(goalUpdateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);

            // delete
            result = goalRepository.Delete(goalCreateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);

            // fetch

            // - make fakes
            var fakes = goalFaker.GetMany(10);

            // - add fakes to database
            List <int?> ids = new List <int?>();

            foreach (var f in fakes)
            {
                result = goalRepository.Create(f);

                Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
                Assert.True(result.Model.GoalId >= 0);
                ids.Add(result.Model.GoalId);
            }

            // - get fakes from database
            foreach (var id in ids)
            {
                var model = new Goal()
                {
                    GoalId = id
                };

                result = goalRepository.Fetch(model);
                Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
                Assert.True(result.Model.GoalId >= 0);
            }
        }
        public void GoalRepository()
        {
            Mock<IDbSetFactory> factory = new Mock<IDbSetFactory>();
            Mock<DbSet<Goal>> dbSet = new Mock<DbSet<Goal>>();

            factory.Setup(m => m.CreateDbSet<Goal>()).Returns(dbSet.Object);

            GoalRepository repo = new GoalRepository(factory.Object);

            var Goal = new Goal();

            var sequence = new MockSequence();
            dbSet.InSequence(sequence).Setup(e => e.Add(Goal));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            repo.Create(Goal);
            repo.Get(Goal.Id);
            repo.Update(Goal);
            repo.Delete(Goal.Id);
        }