Beispiel #1
0
        public void InvokeSaverSaveChangesMethod()
        {
            //Arrange
            var mapperMock        = new Mock <IMappingProvider>();
            var saverMock         = new Mock <ISaver>();
            var userTestsRepoMock = new Mock <IRepository <UserTest> >();

            var data = new List <UserTest>()
            {
                new UserTest {
                    UserId = "1", TestId = 1
                }
            };

            userTestsRepoMock.Setup(x => x.All).Returns(data.AsQueryable);

            var dto = new UserTestDto()
            {
                UserId = "1", TestId = 1
            };

            var resultService = new ResultService(saverMock.Object, mapperMock.Object, userTestsRepoMock.Object);

            ////Act
            resultService.Add(dto);
            //Assert
            saverMock.Verify(x => x.SaveChanges(), Times.Once);
        }
Beispiel #2
0
        public void ThrowArgumentNullException_WhenUserTestDtoIsNull()
        {
            //Arrange
            var mapperMock        = new Mock <IMappingProvider>();
            var saverMock         = new Mock <ISaver>();
            var userTestsRepoMock = new Mock <IRepository <UserTest> >();

            var resultService = new ResultService(saverMock.Object, mapperMock.Object, userTestsRepoMock.Object);

            //Act&Assert
            Assert.ThrowsException <ArgumentNullException>(() => resultService.Add(null));
        }
        private void ProceedNumeration(
            NumerateData numerateData, IDictionary <Element, int> elementsWithNewMarkNumber, bool canBeTypeParameter)
        {
            var uiDoc = _uiApplication.ActiveUIDocument;
            var doc   = uiDoc.Document;

            try
            {
                _uiApplication.Application.FailuresProcessing += ApplicationOnFailuresProcessing;

                var resultService = new ResultService();

                var transactionName = Language.GetFunctionLocalName(new ModPlusConnector());
                if (string.IsNullOrEmpty(transactionName))
                {
                    transactionName = LangItem;
                }
                using (var transaction = new Transaction(doc))
                {
                    transaction.Start(transactionName);

                    var typesToSkip = new List <ElementId>();
                    foreach (var pair in elementsWithNewMarkNumber)
                    {
                        try
                        {
                            var typeId = pair.Key.CanHaveTypeAssigned()
                                ? pair.Key.GetTypeId() ?? ElementId.InvalidElementId
                                : ElementId.InvalidElementId;

                            if (typeId != ElementId.InvalidElementId && typesToSkip.Contains(typeId))
                            {
                                continue;
                            }

                            if (numerateData.GetParameter(pair.Key, canBeTypeParameter, out var isInstanceParameter) is Parameter parameter)
                            {
                                if (!isInstanceParameter && typeId != ElementId.InvalidElementId)
                                {
                                    typesToSkip.Add(typeId);
                                }

                                if (parameter.IsReadOnly)
                                {
                                    // Параметр "..." имеет свойство "Только для чтения" у следующих элементов
                                    resultService.Add(
                                        $"{Language.GetItem("h14")} \"{numerateData.Parameter.Name}\" {Language.GetItem("h15")}:",
                                        pair.Key.Id.IntegerValue.ToString(),
                                        ResultItemType.Info);
                                }
                                else
                                {
                                    SetParameterValue(pair.Key, parameter, numerateData, pair.Value, isInstanceParameter);
                                }
                            }
                        }
                        catch (Autodesk.Revit.Exceptions.OperationCanceledException)
                        {
                            // ignore
                        }
                        catch (Exception exception)
                        {
                            // При изменении значения параметров перечисленных элементов произошли ошибки
                            resultService.Add(
                                $"{Language.GetItem("h17")}: {exception.Message}",
                                pair.Key.Id.IntegerValue.ToString(),
                                ResultItemType.Error);
                        }
                    }

                    transaction.Commit();
                }

                resultService.ShowByType();

                _uiApplication.Application.FailuresProcessing -= ApplicationOnFailuresProcessing;
            }
            catch (Exception exception)
            {
                ExceptionBox.Show(exception);
            }
        }