Exemplo n.º 1
0
        public void TestGetVariant()
        {
            const string variantData    = "Пусть это будут данные варианта. То, что это на самом деле строка, не принципиально.";
            var          allowedVersion = new Version(1, 0, 234, 999);

            var dataServiceMock = new Mock <IVariantProviderServiceClient>(MockBehavior.Strict);
            var taskVariantInfo = new TaskVariantDto
            {
                Data             = Encoding.UTF8.GetBytes(variantData),
                GeneratorVersion = allowedVersion.ToString(),
                Id      = 7,
                Number  = "test",
                Version = 1
            };

            dataServiceMock
            .Setup(srv => srv.GetVariantAsync(It.Is <long>(l => l == TaskId), It.Is <Guid>(g => g == _sessionGuid)))
            .Callback(() => dataServiceMock.Raise(mock => mock.GetVariantCompleted += null,
                                                  new GetVariantCompletedEventArgs(new object[] { taskVariantInfo }, null, false, null)))
            .Verifiable();
            SetupCloseAsync(dataServiceMock);

            using (var wrapper = DisposableWcfClientWrapper.Create(dataServiceMock.Object))
            {
                var variantProvider = new VariantProvider(
                    TaskId,
                    _sessionGuid,
                    new[] { new Version(allowedVersion.Major, allowedVersion.Minor + 1) },
                    wrapper);

                using (var flag = new AutoResetEvent(false))
                {
                    var handled = false;
                    EventHandler <VariantDownloadedEventArgs> handler = (sender, args) =>
                    {
                        Assert.AreSame(sender, variantProvider);
                        Assert.NotNull(args);
                        Assert.That(args.Data.SequenceEqual(taskVariantInfo.Data));
                        Assert.AreEqual(taskVariantInfo.Number, args.Number);
                        Assert.AreEqual(taskVariantInfo.Number, args.Number);
                        handled = true;
                        flag.Set();
                    };

                    variantProvider.VariantDownloaded += handler;
                    variantProvider.DownloadVariantAsync();
                    flag.WaitOne(1000);
                    variantProvider.VariantDownloaded -= handler;

                    Assert.IsTrue(handled);
                }
            }

            dataServiceMock.Verify();
        }
Exemplo n.º 2
0
        public void TestInvalidVersion()
        {
            const string variantData    = "Пусть это будут данные варианта. То, что это на самом деле строка, не принципиально.";
            var          allowedVersion = new Version(1, 0);

            var dataServiceMock = new Mock <IVariantProviderServiceClient>(MockBehavior.Strict);
            var taskVariantInfo = new TaskVariantDto
            {
                Data             = Encoding.UTF8.GetBytes(variantData),
                GeneratorVersion = allowedVersion.ToString(),
                Id      = 7,
                Number  = "test",
                Version = 1
            };

            Assert.Throws <Exception>(() =>
            {
                dataServiceMock
                .Setup(
                    srv => srv.GetVariantAsync(It.Is <long>(l => l == TaskId), It.Is <Guid>(g => g == _sessionGuid)))
                .Callback(() => dataServiceMock.Raise(mock => mock.GetVariantCompleted += null,
                                                      new GetVariantCompletedEventArgs(new object[] { taskVariantInfo }, null, false, null)))
                .Verifiable();
                SetupCloseAsync(dataServiceMock);

                using (var wrapper = DisposableWcfClientWrapper.Create(dataServiceMock.Object))
                {
                    var variantProvider = new VariantProvider(
                        TaskId,
                        _sessionGuid,
                        new[] { new Version(allowedVersion.Major + 1, allowedVersion.Minor) },
                        wrapper);
                    variantProvider.DownloadVariantAsync();
                }
            });
        }
        //добавление-удаление
        /// <summary> Инициализация </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            InitToolBarCommands();

            OnLoadedCmd = new DelegateCommand(
                o =>
            {
                VariantProvider.DownloadVariantAsync();
                ToolBarCommands.ForEach(c => c.RefreshState());
            }, o => true);
            var outV = new Vertex("a");

            VertexClickCmd = new DelegateCommand(
                o =>
            {
                if (_state == State.AddEdge1)
                {
                    outV = GivenGraph.Vertices.Single(v => v.Name == ((IVertex)o).Name) as Vertex;
                    VertVisCol.Single(v => v.Name == outV.Name).Radius     = 23;
                    VertVisCol.Single(v => v.Name == outV.Name).Background = new SolidColorBrush(Colors.Magenta);
                    UserActionsManager.RegisterInfo(string.Format("Выходная вершина - [{0}]. Выберите входную вершину.", ((IVertex)o).Name));
                    _state = State.AddEdge2;
                    return;
                }
                if (_state == State.AddEdge2)
                {
                    var inV = GivenGraph.Vertices.Single(v => v.Name == ((IVertex)o).Name) as Vertex;
                    UserActionsManager.RegisterInfo(string.Format("Входная вершина - [{0}]. Добавьте другое ребро или выйдете из режима добавления ребер", ((IVertex)o).Name));
                    var newEdge = new DirectedEdge(outV, inV);
                    if (GivenGraph.Edges.Any(newEdge.Equals))
                    {
                        ReportMistake("Указанная дуга уже существует.");
                        return;
                    }
                    VertVisCol.Single(v => v.Name == outV.Name).Radius     = 20;
                    VertVisCol.Single(v => v.Name == outV.Name).Background = new SolidColorBrush(Colors.LightGray);

                    GivenGraph.AddEdge(newEdge);
                    _state = State.AddEdge1;
                }
                if (_state == State.RemoveVertex)
                {
                    GivenGraph.RemoveVertex(GivenGraph.Vertices.Single(v => v.Name == ((IVertex)o).Name));
                    UserActionsManager.RegisterInfo(string.Format("Вершина [{0}] удалена со всеми связями", ((IVertex)o).Name));
                }
            },
                o => true);
            VisualizerClickCmd = new DelegateCommand(
                o =>
            {
                if (_state == State.AddVertex)
                {
                    UserActionsManager.RegisterInfo((string.Format("Вершина добавлена")));
                    var vertex  = (Graphs.UIComponents.Visualization.Vertex)o;
                    vertex.Name = (GivenGraph.VerticesCount).ToString();
                    int i       = 0;
                    while (GivenGraph.Vertices.Any(vertex.Equals))
                    {
                        i           = i + 1;
                        vertex.Name = (i).ToString();
                    }
                }
            },
                o => true);
        }
Exemplo n.º 4
0
 /// <summary> Начать загрузку варианта </summary>
 public void StartVariantDownload()
 {
     VariantProvider.DownloadVariantAsync();
 }
 /// <summary> Начать загрузку варианта </summary>
 public void StartVariantDownload()
 {
     VariantProvider.DownloadVariantAsync();
     //OnTaskLoadingComlete(e);
 }