Beispiel #1
0
        public void Put_WithMockedModel_ShouldBeCalledOnce()
        {
            // Arrange
            var actualId       = 8412;
            var dummyString    = Guid.NewGuid().ToString().Replace("-", "");
            var mockRepository = new Mock <IEntryPlatformRepository>();
            var dbModel        = new EntryPlatformModel()
            {
                EntryId     = 8413,
                PlatformId  = 8414,
                Description = dummyString,
            };

            mockRepository
            .Setup(m => m.Update(dbModel));

            var controller = new EntryPlatformController(mockRepository.Object);

            // Act
            controller.Put(actualId, dbModel);

            // Assert
            mockRepository
            .Verify(m => m.Update(
                        It.Is <EntryPlatformModel>(
                            i => i.Id == actualId && i.Description == dummyString)),
                    Times.Once());
        }
Beispiel #2
0
        public void InsertThenUpdate_ShouldReflectChanges()
        {
            // Arrange
            var expectedValue = "*****@*****.**";
            var dummyString   = Guid.NewGuid().ToString().Replace("-", "");
            var dbModel       = new EntryPlatformModel()
            {
                EntryId     = 6,
                PlatformId  = 1,
                Description = dummyString,
            };

            // Act
            var newId = new EntryPlatformRepository(AppState.ConnectionString)
                        .Insert(dbModel);
            var dbModel2 = new EntryPlatformRepository(AppState.ConnectionString)
                           .Select(newId);

            dbModel2.Description = expectedValue;

            new EntryPlatformRepository(AppState.ConnectionString)
            .Update(dbModel2);
            var actualValue = new EntryPlatformRepository(AppState.ConnectionString)
                              .Select(newId)
                              .Description;

            // Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
Beispiel #3
0
        public void Get_WithParameter42_ShouldReturnDbModel()
        {
            // Arrange
            var actualId       = 8412;
            var mockRepository = new Mock <IEntryPlatformRepository>();
            var expectedValue  = new EntryPlatformModel()
            {
                Id          = actualId,
                EntryId     = 8414,
                PlatformId  = 8415,
                Description = "blanditiis"
            };

            mockRepository
            .Setup(m => m.Select(actualId))
            .Returns(expectedValue);

            var controller = new EntryPlatformController(mockRepository.Object);

            // Act
            var result      = controller.Get(actualId) as JsonResult;
            var actualValue = (EntryPlatformModel)result.Value;

            // Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
Beispiel #4
0
        public int Insert(EntryPlatformModel obj)
        {
            var storedProc = "sp_insert_entry_platform";
            var insertObj  = new
            {
                entry_id    = obj.EntryId,
                platform_id = obj.PlatformId,
                description = obj.Description
            };

            return(Insert(storedProc, insertObj));
        }
Beispiel #5
0
        public void Update(EntryPlatformModel obj)
        {
            var storedProc = "sp_update_entry_platform";
            var updateObj  = new
            {
                id          = obj.Id,
                entry_id    = obj.EntryId,
                platform_id = obj.PlatformId,
                description = obj.Description
            };

            Update(storedProc, updateObj);
        }
Beispiel #6
0
        public void InsertAndSelect_ShouldEqualInserted()
        {
            // Arrange
            var dbModel = new EntryPlatformModel()
            {
                EntryId     = 6,
                PlatformId  = 1,
                Description = "voluptate",
            };
            var expectedValue = new EntryPlatformRepository(AppState.ConnectionString)
                                .Insert(dbModel);

            // Act
            var actualValue = new EntryPlatformRepository(AppState.ConnectionString)
                              .Select(expectedValue)
                              .Id;

            // Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
Beispiel #7
0
        public void Post_WithMockedModel_ShouldReturnNewId()
        {
            // Arrange
            var mockRepository = new Mock <IEntryPlatformRepository>();
            var dbModel        = new EntryPlatformModel();
            var expectedValue  = 8412;

            mockRepository
            .Setup(m => m.Insert(dbModel))
            .Returns(expectedValue);

            var controller = new EntryPlatformController(mockRepository.Object);

            // Act
            var result      = controller.Post(dbModel) as JsonResult;
            var actualValue = (int)result.Value;

            // Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
Beispiel #8
0
        public void InsertAndDelete_ShouldNoLongerExistAfterDelete()
        {
            // Arrange
            var expectedValue = 0;
            var dbModel       = new EntryPlatformModel()
            {
                EntryId     = 6,
                PlatformId  = 1,
                Description = "voluptate",
            };

            // Act
            var newId = new EntryPlatformRepository(AppState.ConnectionString).Insert(dbModel);

            new EntryPlatformRepository(AppState.ConnectionString).Delete(newId);
            var actualValue = new EntryPlatformRepository(AppState.ConnectionString)
                              .Select(newId)
                              .Id;

            // Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
Beispiel #9
0
        private static void Process(int column, string value, EntryModel dbModel, ExcelWorksheet ws)
        {
            var entryId = 0;
            var entry   = _entryRepository
                          .SelectList()
                          .Where(x => x.CategoryId.Equals(dbModel.CategoryId))
                          .Where(x => x.SubCategoryId.Equals(dbModel.SubCategoryId))
                          .Where(x => x.LexiconFunction.Equals(dbModel.LexiconFunction))
                          .Where(x => x.Recommendation.Equals(dbModel.Recommendation))
                          .Where(x => x.Notes.Equals(dbModel.Notes))
                          .FirstOrDefault();

            if (entry != null)
            {
                entryId = entry.Id;
            }

            if (entryId.Equals(0))
            {
                entryId = _entryRepository.Insert(dbModel);
            }

            var platFormName = ws.Cells[_appSettings.PlatformLine, column].Value.ToString();
            var playFormId   = _platformRepository
                               .SelectList()
                               .Where(x => x.Description.Equals(platFormName))
                               .FirstOrDefault()
                               .Id;

            var entryPlatform = new EntryPlatformModel()
            {
                Description = value,
                EntryId     = entryId,
                PlatformId  = playFormId
            };

            _entryPlatformRepository.Insert(entryPlatform);
        }
Beispiel #10
0
 public void Put(int id, [FromBody] EntryPlatformModel value)
 {
     value.Id = id;
     EntryPlatformRepository.Update(value);
 }
Beispiel #11
0
 public JsonResult Post([FromBody] EntryPlatformModel value)
 {
     return(new JsonResult(EntryPlatformRepository.Insert(value)));
 }