public void DividingingTwoNumbersShouldReturnCorrectNumber() { //Arrange var calculatorItems = new CalculatorItems { firstNumber = 1234.567, secondNumber = 1.2, operation = '/' }; var expectedResult = calculatorItems.firstNumber / calculatorItems.secondNumber; //Act try { var result = new CalculateAction(calculatorItems).Execute(); //Assert Assert.IsTrue(Math.Abs(result.result - expectedResult) <= double.Epsilon); } catch (Exception exception) { throw new Exception(exception.Message); } }
//減法按鈕 private void Less(object sender, EventArgs e) { //Button less = (Button)sender; //symbol = less.Text; FirstNumber = Convert.ToInt32(screen.Text); screen.Text = ""; action = CalculateLess; }
//等於按鈕 private void equals(object sender, EventArgs e) { SecondNumber = Convert.ToInt32(screen.Text); string result = "0"; CalculateAction kk = new CalculateAction(action); result = kk(FirstNumber, SecondNumber); //switch (symbol) //{ // case "+": // result = FirstNumber + SecondNumber; // break; // case "-": // result = FirstNumber - SecondNumber; // break; //} screen.Text = result; }
public void DivindingByZeroShouldReturnInfinity() { //Arrange var calculatorItems = new CalculatorItems { firstNumber = 1234.567, secondNumber = 0, operation = '/' }; //Act try { var expectedResult = new CalculateAction(calculatorItems).Execute(); //Assert Assert.IsTrue(double.IsInfinity(expectedResult.result)); } catch (Exception exception) { throw new Exception(exception.Message); } }
static void Main(string[] args) { var repositoryManagerApi = new RepositoryManagerApi(); var emloyeesListAction = new ShowEmployeesAction(repositoryManagerApi.GetEmployeeApi(), repositoryManagerApi.GetPositionApi(), repositoryManagerApi.GetRuleApi(), repositoryManagerApi.GetOwerworkApi(), repositoryManagerApi.GetPaymentApi(), repositoryManagerApi.GetHolidayApi()); var addAction = new AddAction(repositoryManagerApi.GetEmployeeApi(), repositoryManagerApi.GetPositionApi(), repositoryManagerApi.GetRuleApi(), repositoryManagerApi.GetOwerworkApi(), repositoryManagerApi.GetPaymentApi(), repositoryManagerApi.GetHolidayApi()); var removeAction = new RemoveAction(repositoryManagerApi.GetEmployeeApi(), repositoryManagerApi.GetPositionApi(), repositoryManagerApi.GetRuleApi()); var calculateAction = new CalculateAction(repositoryManagerApi.GetCalculatorApi(), repositoryManagerApi.GetEmployeeApi()); var demo = new DemoDataGenerator(repositoryManagerApi); demo.Generate(); new MenuBuilder() .Title("Main menu") .Repeatable() .Item("Show", emloyeesListAction) .Item("Calculate money and hourse", calculateAction) .Item("Add", addAction) .Item("Remove", removeAction) .Exit("Exit") .GetMenu() .Run(); }
public void Calculate(IList <IExplorerTreeItem> items) { _items = items; if (items != null) { Connectors = items.Count(a => !string.IsNullOrEmpty(a.ResourceType) && a.ResourceType.Contains(@"Service") && a.ResourceType != @"WorkflowService" && a.ResourceType != @"ReservedService"); Services = items.Count(a => !string.IsNullOrEmpty(a.ResourceType) && a.ResourceType == @"WorkflowService" && a.IsResourceChecked == true); Sources = items.Count(a => !string.IsNullOrEmpty(a.ResourceType) && IsSource(a.ResourceType) && a.IsResourceChecked == true); Unknown = items.Count(a => a.ResourceType == @"Unknown" || string.IsNullOrEmpty(a.ResourceType)); if (_destination.SelectedEnvironment != null) { var explorerItemViewModels = _destination.SelectedEnvironment.UnfilteredChildren.Flatten(model => model.UnfilteredChildren ?? new ObservableCollection <IExplorerItemViewModel>()); var explorerTreeItems = explorerItemViewModels as IExplorerItemViewModel[] ?? explorerItemViewModels.ToArray(); var idConflicts = from b in explorerTreeItems join explorerTreeItem in items on b.ResourceId equals explorerTreeItem.ResourceId where b.ResourceType != @"Folder" && explorerTreeItem.ResourceType != @"Folder" && explorerTreeItem.IsResourceChecked.HasValue && explorerTreeItem.IsResourceChecked.Value select new Conflict { SourceName = explorerTreeItem.ResourcePath, DestinationName = b.ResourcePath, DestinationId = b.ResourceId, SourceId = explorerTreeItem.ResourceId }; var pathConflicts = from b in explorerTreeItems join explorerTreeItem in items on b.ResourcePath equals explorerTreeItem.ResourcePath where b.ResourceType != @"Folder" && explorerTreeItem.ResourceType != @"Folder" && explorerTreeItem.IsResourceChecked.HasValue && explorerTreeItem.IsResourceChecked.Value select new Conflict { SourceName = explorerTreeItem.ResourcePath, DestinationName = b.ResourcePath, DestinationId = b.ResourceId, SourceId = explorerTreeItem.ResourceId }; var allConflicts = new List <Conflict>(); allConflicts.AddRange(idConflicts); allConflicts.AddRange(pathConflicts); _conflicts = allConflicts.Distinct(new ConflictEqualityComparer()).ToList(); _new = items.Where(p => p.IsResourceChecked == true && Conflicts.All(c => p.ResourceId != c.SourceId)).Except(explorerTreeItems); var ren = from b in explorerTreeItems join explorerTreeItem in items on new { b.ResourcePath } equals new { explorerTreeItem.ResourcePath } where b.ResourceType != @"Folder" && explorerTreeItem.ResourceType != @"Folder" && explorerTreeItem.IsResourceChecked.HasValue && explorerTreeItem.IsResourceChecked.Value select new { SourceName = explorerTreeItem.ResourcePath, DestinationName = b.ResourcePath, SourceId = explorerTreeItem.ResourceId, DestinationId = b.ResourceId }; var errors = ren.Where(ax => ax.SourceId != ax.DestinationId).ToArray(); if (errors.Any()) { RenameErrors = Resources.Languages.Core.DeployResourcesSamePathAndName; foreach (var error in errors) { RenameErrors += $"\n{error.SourceName}-->{error.DestinationName}"; } RenameErrors += Environment.NewLine + Resources.Languages.Core.DeployRenameBeforeContinue; } else { RenameErrors = @""; } } else { _conflicts = new List <Conflict>(); _new = new List <IExplorerTreeItem>(); } Overrides = Conflicts.Count; NewResources = New.Count; } else { Connectors = 0; Services = 0; Sources = 0; Unknown = 0; _conflicts = new List <Conflict>(); _new = new List <IExplorerTreeItem>(); } OnPropertyChanged(() => Conflicts); OnPropertyChanged(() => New); CalculateAction?.Invoke(); CheckDestinationPersmisions(); }