Пример #1
0
        public TodoNotesFaker(IManageDatabase databaseManager, ILogger logger)
        {
            var random       = new Random();
            int randomNumber = random.Next();

            Bogus.Randomizer.Seed = new Random(randomNumber);

            var parentFaker      = new TodoEntryFaker(databaseManager, logger);
            var parent           = parentFaker.GetOne();
            var parentRepository = new TodoEntryRepository(databaseManager, new TodoEntryRepositorySql(), logger);
            var parentAddResult  = parentRepository.Create(parent);

            parent = parentAddResult.Model;

            _faker = new Bogus.Faker <TodoNotes>()
                     .StrictMode(false)
                     .Rules((f, m) =>
            {
                m.TodoNotesId = null;
                m.TodoEntryId = parent.TodoEntryId;
                m.Note        = f.Lorem.Sentence(10);
            });
        }
Пример #2
0
        public void CreateUpdateDeleteFetch()
        {
            // file system
            var path         = "/shop/randomsilo/modern-web/backends/TodoList";
            var project      = "TodoList";
            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 todoEntryRepository = new TodoEntryRepository(databaseManager, new TodoEntryRepositorySql(), logger);

            Assert.NotNull(todoEntryRepository);

            // faker
            BrashActionResult <TodoEntry> result = null;
            var todoEntryFaker = new TodoEntryFaker(databaseManager, logger);

            Assert.NotNull(todoEntryFaker);

            // create
            var todoEntryCreateModel = todoEntryFaker.GetOne();

            result = todoEntryRepository.Create(todoEntryCreateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
            Assert.True(result.Model.TodoEntryId > 0);

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

            // update
            var todoEntryUpdateModel = todoEntryFaker.GetOne();

            todoEntryUpdateModel.TodoEntryId = todoEntryCreateModel.TodoEntryId;
            result = todoEntryRepository.Update(todoEntryUpdateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);

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

            // fetch

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

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

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

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

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

                result = todoEntryRepository.Fetch(model);
                Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
                Assert.True(result.Model.TodoEntryId >= 0);
            }
        }